def get_resources(self): resources = [] instances = extensions.ResourceExtension('{tenant_id}/mgmt/instances', MgmtInstanceController(), member_actions={ 'root': 'GET', 'diagnostics': 'GET', 'hwinfo': 'GET', 'rpc_ping': 'GET', 'action': 'POST' }) resources.append(instances) clusters = extensions.ResourceExtension( '{tenant_id}/mgmt/clusters', MgmtClusterController(), member_actions={'action': 'POST'}) resources.append(clusters) hosts = extensions.ResourceExtension('{tenant_id}/mgmt/hosts', HostController(), member_actions={}) resources.append(hosts) quota = extensions.ResourceExtension('{tenant_id}/mgmt/quotas', QuotaController(), member_actions={}) resources.append(quota) storage = extensions.ResourceExtension('{tenant_id}/mgmt/storage', StorageController(), member_actions={}) resources.append(storage) host_instances = extensions.ResourceExtension( 'instances', hostservice.HostInstanceController(), parent={ 'member_name': 'host', 'collection_name': '{tenant_id}/mgmt/hosts' }, collection_actions={'action': 'POST'}) resources.append(host_instances) upgrade = extensions.ResourceExtension( '{tenant_id}/mgmt/instances/{instance_id}/upgrade', UpgradeController(), member_actions={}) resources.append(upgrade) datastore_configuration_parameters = extensions.ResourceExtension( '{tenant_id}/mgmt/datastores/versions/{version_id}/parameters', conf_service.ConfigurationsParameterController(), member_actions={}) resources.append(datastore_configuration_parameters) return resources
def setUp(self): super(TestClusterController, self).setUp() self.context = trove_testtools.TroveTestContext(self) self.req = Mock() self.req.environ = Mock() self.req.environ.__getitem__ = Mock(return_value=self.context) mock_cluster1 = Mock() mock_cluster1.datastore_version.manager = 'vertica' mock_cluster1.instances = [] mock_cluster1.instances_without_server = [] mock_cluster2 = Mock() mock_cluster2.datastore_version.manager = 'vertica' mock_cluster2.instances = [] mock_cluster2.instances_without_server = [] self.mock_clusters = [mock_cluster1, mock_cluster2] self.controller = MgmtClusterController()
def get_resources(self): resources = [] instances = extensions.ResourceExtension( '{tenant_id}/mgmt/instances', MgmtInstanceController(), member_actions={'root': 'GET', 'diagnostics': 'GET', 'hwinfo': 'GET', 'rpc_ping': 'GET', 'action': 'POST'}) resources.append(instances) clusters = extensions.ResourceExtension( '{tenant_id}/mgmt/clusters', MgmtClusterController(), member_actions={'action': 'POST'}) resources.append(clusters) quota = extensions.ResourceExtension( '{tenant_id}/mgmt/quotas', QuotaController(), member_actions={}) resources.append(quota) upgrade = extensions.ResourceExtension( '{tenant_id}/mgmt/instances/{instance_id}/upgrade', UpgradeController(), member_actions={}) resources.append(upgrade) datastore_configuration_parameters = extensions.ResourceExtension( '{tenant_id}/mgmt/datastores/versions/{version_id}/parameters', conf_service.ConfigurationsParameterController(), member_actions={}) resources.append(datastore_configuration_parameters) datastore_version = extensions.ResourceExtension( '{tenant_id}/mgmt/datastore-versions', DatastoreVersionController(), member_actions={}) resources.append(datastore_version) return resources
def setUp(self): super(TestClusterController, self).setUp() self.context = trove_testtools.TroveTestContext(self) self.req = Mock() self.req.environ = Mock() self.req.environ.__getitem__ = Mock(return_value=self.context) mock_cluster1 = Mock() mock_cluster1.datastore_version.manager = "vertica" mock_cluster1.instances = [] mock_cluster1.instances_without_server = [] mock_cluster2 = Mock() mock_cluster2.datastore_version.manager = "vertica" mock_cluster2.instances = [] mock_cluster2.instances_without_server = [] self.mock_clusters = [mock_cluster1, mock_cluster2] self.controller = MgmtClusterController()
class TestClusterController(trove_testtools.TestCase): def setUp(self): super(TestClusterController, self).setUp() self.context = trove_testtools.TroveTestContext(self) self.req = Mock() self.req.environ = Mock() self.req.environ.__getitem__ = Mock(return_value=self.context) mock_cluster1 = Mock() mock_cluster1.datastore_version.manager = "vertica" mock_cluster1.instances = [] mock_cluster1.instances_without_server = [] mock_cluster2 = Mock() mock_cluster2.datastore_version.manager = "vertica" mock_cluster2.instances = [] mock_cluster2.instances_without_server = [] self.mock_clusters = [mock_cluster1, mock_cluster2] self.controller = MgmtClusterController() def tearDown(self): super(TestClusterController, self).tearDown() def test_get_action_schema(self): body = {"do_stuff": {}} action_schema = Mock() action_schema.get = Mock() self.controller.get_action_schema(body, action_schema) action_schema.get.assert_called_with("do_stuff", {}) @patch.object(MgmtCluster, "load") def test_show_cluster(self, mock_cluster_load): tenant_id = Mock() id = Mock() mock_cluster_load.return_value = self.mock_clusters[0] self.controller.show(self.req, tenant_id, id) mock_cluster_load.assert_called_with(self.context, id) @patch.object(MgmtCluster, "load_all") def test_index_cluster(self, mock_cluster_load_all): tenant_id = Mock() mock_cluster_load_all.return_value = self.mock_clusters self.controller.index(self.req, tenant_id) mock_cluster_load_all.assert_called_with(self.context, deleted=None) @patch.object(MgmtCluster, "load") def test_controller_action_found(self, mock_cluster_load): body = {"reset-task": {}} tenant_id = Mock() id = Mock() mock_cluster_load.return_value = self.mock_clusters[0] result = self.controller.action(self.req, body, tenant_id, id) self.assertEqual(202, result.status) self.assertIsNotNone(result.data) def test_controller_no_body_action_found(self): tenant_id = Mock() id = Mock() self.assertRaisesRegexp( exception.BadRequest, "Invalid request body.", self.controller.action, self.req, None, tenant_id, id ) @patch.object(MgmtCluster, "load") def test_controller_invalid_action_found(self, mock_cluster_load): body = {"do_stuff": {}} tenant_id = Mock() id = Mock() mock_cluster_load.return_value = self.mock_clusters[0] self.assertRaisesRegexp( exception.BadRequest, "Invalid cluster action requested.", self.controller.action, self.req, body, tenant_id, id, )
class TestClusterController(trove_testtools.TestCase): def setUp(self): super(TestClusterController, self).setUp() self.context = trove_testtools.TroveTestContext(self) self.req = Mock() self.req.environ = Mock() self.req.environ.__getitem__ = Mock(return_value=self.context) mock_cluster1 = Mock() mock_cluster1.datastore_version.manager = 'vertica' mock_cluster1.instances = [] mock_cluster1.instances_without_server = [] mock_cluster2 = Mock() mock_cluster2.datastore_version.manager = 'vertica' mock_cluster2.instances = [] mock_cluster2.instances_without_server = [] self.mock_clusters = [mock_cluster1, mock_cluster2] self.controller = MgmtClusterController() def tearDown(self): super(TestClusterController, self).tearDown() def test_get_action_schema(self): body = {'do_stuff': {}} action_schema = Mock() action_schema.get = Mock() self.controller.get_action_schema(body, action_schema) action_schema.get.assert_called_with('do_stuff', {}) @patch.object(MgmtCluster, 'load') def test_show_cluster(self, mock_cluster_load): tenant_id = Mock() id = Mock() mock_cluster_load.return_value = self.mock_clusters[0] self.controller.show(self.req, tenant_id, id) mock_cluster_load.assert_called_with(self.context, id) @patch.object(MgmtCluster, 'load_all') def test_index_cluster(self, mock_cluster_load_all): tenant_id = Mock() mock_cluster_load_all.return_value = self.mock_clusters self.controller.index(self.req, tenant_id) mock_cluster_load_all.assert_called_with(self.context, deleted=None) @patch.object(MgmtCluster, 'load') def test_controller_action_found(self, mock_cluster_load): body = {'reset-task': {}} tenant_id = Mock() id = Mock() mock_cluster_load.return_value = self.mock_clusters[0] result = self.controller.action(self.req, body, tenant_id, id) self.assertEqual(202, result.status) self.assertIsNotNone(result.data) def test_controller_no_body_action_found(self): tenant_id = Mock() id = Mock() self.assertRaisesRegex(exception.BadRequest, 'Invalid request body.', self.controller.action, self.req, None, tenant_id, id) @patch.object(MgmtCluster, 'load') def test_controller_invalid_action_found(self, mock_cluster_load): body = {'do_stuff': {}} tenant_id = Mock() id = Mock() mock_cluster_load.return_value = self.mock_clusters[0] self.assertRaisesRegex(exception.BadRequest, 'Invalid cluster action requested.', self.controller.action, self.req, body, tenant_id, id)