本文整理汇总了Python中trove.cluster.service.ClusterController类的典型用法代码示例。如果您正苦于以下问题:Python ClusterController类的具体用法?Python ClusterController怎么用?Python ClusterController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClusterController类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(TestClusterController, self).setUp()
self.controller = ClusterController()
instances = [
{
"flavorRef": "7",
"volume": {
"size": 1
},
"availability_zone": "az",
"nics": [
{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}
]
}
] * 5
self.cluster = {
"cluster": {
"name": "products",
"datastore": {
"type": "mongodb",
"version": "2.4.10"
},
"instances": instances
}
}
self.add_shard = {
"add_shard": {}
}
开发者ID:edwardt,项目名称:trove,代码行数:29,代码来源:test_cluster_controller.py
示例2: setUp
def setUp(self):
super(TestClusterControllerWithStrategy, self).setUp()
self.controller = ClusterController()
self.cluster = {
"cluster": {
"name": "products",
"datastore": {
"type": "redis",
"version": "3.0"
},
"instances": [
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
]
}
}
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:32,代码来源:test_cluster_redis_controller.py
示例3: setUp
def setUp(self):
super(TestClusterController, self).setUp()
self.controller = ClusterController()
self.cluster = {
"cluster": {
"name": "products",
"datastore": {
"type": "mongodb",
"version": "2.4.10"
},
"instances": [
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
}
]
}
}
self.add_shard = {
"add_shard": {}
}
开发者ID:CMSS-BCRDB,项目名称:RDSV1.0,代码行数:47,代码来源:test_cluster_controller.py
示例4: TestClusterController
class TestClusterController(trove_testtools.TestCase):
def setUp(self):
super(TestClusterController, self).setUp()
self.controller = ClusterController()
instances = [
{
"volume_size": None,
"flavorRef": "7",
"availability_zone": "az",
"nics": [
{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}
]
},
{
"volume_size": None,
"flavorRef": "8",
"availability_zone": "az",
"nics": [
{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}
]
},
{
"volume_size": None,
"flavorRef": "7",
"availability_zone": "az",
"nics": [
{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}
]
}
]
self.cluster = {
"cluster": {
"name": "products",
"datastore": {
"type": "redis",
"version": "3.0"
},
"instances": instances
}
}
def test_get_schema_create(self):
schema = self.controller.get_schema('create', self.cluster)
self.assertIsNotNone(schema)
self.assertTrue('cluster' in schema['properties'])
self.assertTrue('cluster')
def test_validate_create(self):
body = self.cluster
schema = self.controller.get_schema('create', body)
validator = jsonschema.Draft4Validator(schema)
self.assertTrue(validator.is_valid(body))
def test_validate_create_blankname(self):
body = self.cluster
body['cluster']['name'] = " "
schema = self.controller.get_schema('create', body)
validator = jsonschema.Draft4Validator(schema)
self.assertFalse(validator.is_valid(body))
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
self.assertThat(len(errors), Is(1))
self.assertThat(errors[0].message,
Equals("' ' does not match '^.*[0-9a-zA-Z]+.*$'"))
def test_validate_create_blank_datastore(self):
body = self.cluster
body['cluster']['datastore']['type'] = ""
schema = self.controller.get_schema('create', body)
validator = jsonschema.Draft4Validator(schema)
self.assertFalse(validator.is_valid(body))
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
error_messages = [error.message for error in errors]
error_paths = [error.path.pop() for error in errors]
self.assertThat(len(errors), Is(2))
self.assertIn("'' is too short", error_messages)
self.assertIn("'' does not match '^.*[0-9a-zA-Z]+.*$'", error_messages)
self.assertIn("type", error_paths)
@patch.object(Cluster, 'create')
@patch.object(datastore_models, 'get_datastore_version')
def test_create_clusters_disabled(self,
mock_get_datastore_version,
mock_cluster_create):
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'mysql'
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaisesRegexp(exception.ClusterDatastoreNotSupported,
"Clusters not supported for",
self.controller.create,
req,
#.........这里部分代码省略.........
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:101,代码来源:test_cluster_redis_controller.py
示例5: TestClusterControllerWithStrategy
class TestClusterControllerWithStrategy(trove_testtools.TestCase):
def setUp(self):
super(TestClusterControllerWithStrategy, self).setUp()
self.controller = ClusterController()
self.cluster = {
"cluster": {
"name": "products",
"datastore": {
"type": "redis",
"version": "3.0"
},
"instances": [
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
]
}
}
def tearDown(self):
super(TestClusterControllerWithStrategy, self).tearDown()
cfg.CONF.clear_override('cluster_support', group='redis')
cfg.CONF.clear_override('api_strategy', group='redis')
@patch.object(datastore_models, 'get_datastore_version')
@patch.object(models.Cluster, 'create')
def test_create_clusters_disabled(self,
mock_cluster_create,
mock_get_datastore_version):
cfg.CONF.set_override('cluster_support', False, group='redis',
enforce_type=True)
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'redis'
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaisesRegexp(exception.TroveError,
"Clusters not supported for",
self.controller.create,
req,
body,
tenant_id)
@patch.object(views.ClusterView, 'data', return_value={})
@patch.object(datastore_models, 'get_datastore_version')
@patch.object(models.Cluster, 'create')
def test_create_clusters_enabled(self,
mock_cluster_create,
mock_get_datastore_version,
mock_cluster_view_data):
cfg.CONF.set_override('cluster_support', True, group='redis',
enforce_type=True)
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'redis'
mock_get_datastore_version.return_value = (Mock(), datastore_version)
mock_cluster = Mock()
mock_cluster.datastore_version.manager = 'redis'
mock_cluster_create.return_value = mock_cluster
self.controller.create(req, body, tenant_id)
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:94,代码来源:test_cluster_redis_controller.py
示例6: TestClusterControllerWithStrategy
class TestClusterControllerWithStrategy(TestCase):
def setUp(self):
super(TestClusterControllerWithStrategy, self).setUp()
self.controller = ClusterController()
self.cluster = {
"cluster": {
"name": "products",
"datastore": {
"type": "mongodb",
"version": "2.4.10"
},
"instances": [
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
}
]
}
}
def tearDown(self):
super(TestClusterControllerWithStrategy, self).tearDown()
cfg.CONF.clear_override('cluster_support', group='mongodb')
cfg.CONF.clear_override('api_strategy', group='mongodb')
@patch.object(datastore_models, 'get_datastore_version')
@patch.object(models.Cluster, 'create')
def test_create_clusters_disabled(self,
mock_cluster_create,
mock_get_datastore_version):
cfg.CONF.set_override('cluster_support', False, group='mongodb')
body = self.cluster
tenant_id = Mock()
context = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'mongodb'
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaises(exception.TroveError, self.controller.create, req,
body, tenant_id)
@patch.object(views.ClusterView, 'data', return_value={})
@patch.object(datastore_models, 'get_datastore_version')
@patch.object(models.Cluster, 'create')
def test_create_clusters_enabled(self,
mock_cluster_create,
mock_get_datastore_version,
mock_cluster_view_data):
cfg.CONF.set_override('cluster_support', True, group='mongodb')
body = self.cluster
tenant_id = Mock()
context = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'mongodb'
mock_get_datastore_version.return_value = (Mock(), datastore_version)
mock_cluster = Mock()
mock_cluster.datastore_version.manager = 'mongodb'
mock_cluster_create.return_value = mock_cluster
self.controller.create(req, body, tenant_id)
#.........这里部分代码省略.........
开发者ID:edwardt,项目名称:trove,代码行数:101,代码来源:test_cluster_controller.py
示例7: TestClusterController
class TestClusterController(TestCase):
def setUp(self):
super(TestClusterController, self).setUp()
self.controller = ClusterController()
self.cluster = {
"cluster": {
"name": "products",
"datastore": {
"type": "vertica",
"version": "7.1"
},
"instances": [
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
{
"flavorRef": "7",
"volume": {
"size": 1
},
},
]
}
}
def test_get_schema_create(self):
schema = self.controller.get_schema('create', self.cluster)
self.assertIsNotNone(schema)
self.assertTrue('cluster' in schema['properties'])
self.assertTrue('cluster')
def test_validate_create(self):
body = self.cluster
schema = self.controller.get_schema('create', body)
validator = jsonschema.Draft4Validator(schema)
self.assertTrue(validator.is_valid(body))
def test_validate_create_blankname(self):
body = self.cluster
body['cluster']['name'] = " "
schema = self.controller.get_schema('create', body)
validator = jsonschema.Draft4Validator(schema)
self.assertFalse(validator.is_valid(body))
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
self.assertThat(len(errors), Is(1))
self.assertThat(errors[0].message,
Equals("' ' does not match '^.*[0-9a-zA-Z]+.*$'"))
def test_validate_create_blank_datastore(self):
body = self.cluster
body['cluster']['datastore']['type'] = ""
schema = self.controller.get_schema('create', body)
validator = jsonschema.Draft4Validator(schema)
self.assertFalse(validator.is_valid(body))
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
error_messages = [error.message for error in errors]
error_paths = [error.path.pop() for error in errors]
self.assertThat(len(errors), Is(2))
self.assertIn("'' is too short", error_messages)
self.assertIn("'' does not match '^.*[0-9a-zA-Z]+.*$'", error_messages)
self.assertIn("type", error_paths)
@patch.object(Cluster, 'create')
@patch.object(datastore_models, 'get_datastore_version')
def test_create_clusters_disabled(self,
mock_get_datastore_version,
mock_cluster_create):
body = self.cluster
tenant_id = Mock()
context = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = 'mysql'
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaises(exception.ClusterDatastoreNotSupported,
self.controller.create,
req,
body,
tenant_id)
@patch.object(Cluster, 'create')
@patch.object(utils, 'get_id_from_href')
@patch.object(datastore_models, 'get_datastore_version')
def test_create_clusters(self,
mock_get_datastore_version,
mock_id_from_href,
#.........这里部分代码省略.........
开发者ID:CMSS-BCRDB,项目名称:RDSV1.0,代码行数:101,代码来源:test_cluster_vertica_controller.py
示例8: TestClusterController
class TestClusterController(TestCase):
def setUp(self):
super(TestClusterController, self).setUp()
self.controller = ClusterController()
self.locality = "anti-affinity"
instances = [
{
"flavorRef": "7",
"volume": {"size": 1},
"availability_zone": "az",
"nics": [{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}],
}
] * 5
self.cluster = {
"cluster": {
"name": "products",
"datastore": {"type": "mongodb", "version": "2.4.10"},
"instances": instances,
"locality": self.locality,
}
}
self.add_shard = {"add_shard": {}}
def test_get_schema_create(self):
schema = self.controller.get_schema("create", self.cluster)
self.assertIsNotNone(schema)
self.assertTrue("cluster" in schema["properties"])
self.assertTrue("cluster")
def test_get_schema_action_add_shard(self):
schema = self.controller.get_schema("add_shard", self.add_shard)
self.assertIsNotNone(schema)
self.assertTrue("add_shard" in schema["properties"])
def test_validate_create(self):
body = self.cluster
schema = self.controller.get_schema("create", body)
validator = jsonschema.Draft4Validator(schema)
self.assertTrue(validator.is_valid(body))
def test_validate_add_shard(self):
body = self.add_shard
schema = self.controller.get_schema("add_shard", body)
validator = jsonschema.Draft4Validator(schema)
self.assertTrue(validator.is_valid(body))
def test_validate_create_blankname(self):
body = self.cluster
body["cluster"]["name"] = " "
schema = self.controller.get_schema("create", body)
validator = jsonschema.Draft4Validator(schema)
self.assertFalse(validator.is_valid(body))
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
self.assertThat(len(errors), Is(1))
self.assertThat(errors[0].message, Equals("' ' does not match '^.*[0-9a-zA-Z]+.*$'"))
def test_validate_create_blank_datastore(self):
body = self.cluster
body["cluster"]["datastore"]["type"] = ""
schema = self.controller.get_schema("create", body)
validator = jsonschema.Draft4Validator(schema)
self.assertFalse(validator.is_valid(body))
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
error_messages = [error.message for error in errors]
error_paths = [error.path.pop() for error in errors]
self.assertThat(len(errors), Is(2))
self.assertIn("'' is too short", error_messages)
self.assertIn("'' does not match '^.*[0-9a-zA-Z]+.*$'", error_messages)
self.assertIn("type", error_paths)
def test_validate_create_bad_locality(self):
body = self.cluster
body["cluster"]["locality"] = "$%^&"
schema = self.controller.get_schema("create", body)
validator = jsonschema.Draft4Validator(schema)
self.assertFalse(validator.is_valid(body))
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
error_messages = [error.message for error in errors]
error_paths = [error.path.pop() for error in errors]
self.assertThat(len(errors), Is(1))
self.assertIn("'$%^&' does not match '^.*[0-9a-zA-Z]+.*$'", error_messages)
self.assertIn("locality", error_paths)
@patch.object(Cluster, "create")
@patch.object(datastore_models, "get_datastore_version")
def test_create_clusters_disabled(self, mock_get_datastore_version, mock_cluster_create):
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = "mysql"
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaises(exception.ClusterDatastoreNotSupported, self.controller.create, req, body, tenant_id)
#.........这里部分代码省略.........
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:101,代码来源:test_cluster_controller.py
示例9: TestClusterControllerWithStrategy
class TestClusterControllerWithStrategy(TestCase):
def setUp(self):
super(TestClusterControllerWithStrategy, self).setUp()
self.controller = ClusterController()
self.cluster = {
"cluster": {
"name": "products",
"datastore": {"type": "mongodb", "version": "2.4.10"},
"instances": [
{"flavorRef": "7", "volume": {"size": 1}},
{"flavorRef": "7", "volume": {"size": 1}},
{"flavorRef": "7", "volume": {"size": 1}},
{"flavorRef": "7", "volume": {"size": 1}},
{"flavorRef": "7", "volume": {"size": 1}},
],
}
}
def tearDown(self):
super(TestClusterControllerWithStrategy, self).tearDown()
cfg.CONF.clear_override("cluster_support", group="mongodb")
cfg.CONF.clear_override("api_strategy", group="mongodb")
@patch.object(datastore_models, "get_datastore_version")
@patch.object(models.Cluster, "create")
def test_create_clusters_disabled(self, mock_cluster_create, mock_get_datastore_version):
cfg.CONF.set_override("cluster_support", False, group="mongodb", enforce_type=True)
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = "mongodb"
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaises(exception.TroveError, self.controller.create, req, body, tenant_id)
@patch.object(views.ClusterView, "data", return_value={})
@patch.object(datastore_models, "get_datastore_version")
@patch.object(models.Cluster, "create")
def test_create_clusters_enabled(self, mock_cluster_create, mock_get_datastore_version, mock_cluster_view_data):
cfg.CONF.set_override("cluster_support", True, group="mongodb", enforce_type=True)
body = self.cluster
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = "mongodb"
mock_get_datastore_version.return_value = (Mock(), datastore_version)
mock_cluster = Mock()
mock_cluster.datastore_version.manager = "mongodb"
mock_cluster_create.return_value = mock_cluster
self.controller.create(req, body, tenant_id)
@patch.object(models.Cluster, "load")
def test_controller_action_multi_action(self, mock_cluster_load):
body = {"do_stuff": {}, "do_stuff2": {}}
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
cluster_id = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
cluster = Mock()
cluster.instances_without_server = [Mock()]
cluster.datastore_version.manager = "test_dsv"
mock_cluster_load.return_value = cluster
self.assertRaisesRegexp(
exception.TroveError,
"should have exactly one action specified",
self.controller.action,
req,
body,
tenant_id,
cluster_id,
)
@patch.object(models.Cluster, "load")
def test_controller_action_no_strategy(self, mock_cluster_load):
body = {"do_stuff2": {}}
tenant_id = Mock()
context = trove_testtools.TroveTestContext(self)
#.........这里部分代码省略.........
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:101,代码来源:test_cluster_controller.py
示例10: TestClusterControllerWithStrategy
class TestClusterControllerWithStrategy(trove_testtools.TestCase):
def setUp(self):
super(TestClusterControllerWithStrategy, self).setUp()
self.controller = ClusterController()
self.cluster = {
"cluster": {
"name": "products",
"datastore": {"type": "pxc", "version": "5.5"},
"instances": [
{"flavorRef": "7", "volume": {"size": 1}},
{"flavorRef": "7", "volume": {"size": 1}},
{"flavorRef": "7", "volume": {"size": 1}},
],
}
}
def tearDown(self):
super(TestClusterControllerWithStrategy, self).tearDown()
cfg.CONF.clear_override("cluster_support", group="pxc")
cfg.CONF.clear_override("api_strategy", group="pxc")
@patch.object(datastore_models, "get_datastore_version")
@patch.object(models.Cluster, "create")
def test_create_clusters_disabled(self, mock_cluster_create, mock_get_datastore_version):
cfg.CONF.set_override("cluster_support", False, group="pxc", enforce_type=True)
body = self.cluster
tenant_id = Mock()
context = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = "pxc"
mock_get_datastore_version.return_value = (Mock(), datastore_version)
self.assertRaises(exception.TroveError, self.controller.create, req, body, tenant_id)
@patch.object(views.ClusterView, "data", return_value={})
@patch.object(datastore_models, "get_datastore_version")
@patch.object(models.Cluster, "create")
def test_create_clusters_enabled(self, mock_cluster_create, mock_get_datastore_version, mock_cluster_view_data):
cfg.CONF.set_override("cluster_support", True, group="pxc", enforce_type=True)
body = self.cluster
tenant_id = Mock()
context = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
datastore_version = Mock()
datastore_version.manager = "pxc"
mock_get_datastore_version.return_value = (Mock(), datastore_version)
mock_cluster = Mock()
mock_cluster.datastore_version.manager = "pxc"
mock_cluster_create.return_value = mock_cluster
self.controller.create(req, body, tenant_id)
@patch.object(models.Cluster, "load")
def test_controller_action_no_strategy(self, mock_cluster_load):
body = {"do_stuff2": {}}
tenant_id = Mock()
context = Mock()
id = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
cluster = Mock()
cluster.datastore_version.manager = "pxc"
mock_cluster_load.return_value = cluster
self.assertRaises(exception.TroveError, self.controller.action, req, body, tenant_id, id)
@patch.object(strategy, "load_api_strategy")
@patch.object(models.Cluster, "load")
def test_controller_action_found(self, mock_cluster_load, mock_cluster_api_strategy):
body = {"do_stuff": {}}
tenant_id = Mock()
context = Mock()
id = Mock()
req = Mock()
req.environ = MagicMock()
req.environ.get = Mock(return_value=context)
cluster = Mock()
cluster.datastore_version.manager = "pxc"
mock_cluster_load.return_value = cluster
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:trove,代码行数:101,代码来源:test_cluster_pxc_controller.py
注:本文中的trove.cluster.service.ClusterController类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论