def setUp(self): super(TestConfigurationParameterList, self).setUp() self.cmd = database_configurations.\ ListDatabaseConfigurationParameters(self.app, None) data = [self.fake_configuration_params.get_params_connect_timeout()] self.configuration_params_client.parameters.return_value =\ common.Paginated(data) self.configuration_params_client.parameters_by_version.return_value =\ common.Paginated(data)
def setUp(self): super(TestConfigurationInstancesList, self).setUp() self.cmd = database_configurations.ListDatabaseConfigurationInstances( self.app, None) data = (self.fake_configurations.get_configuration_instances()) self.configuration_client.instances.return_value = common.Paginated( data)
def setUp(self): super(PaginatedTest, self).setUp() self.items_ = ["item1", "item2"] self.next_marker_ = "next-marker" self.links_ = ["link1", "link2"] self.pgn = common.Paginated(self.items_, self.next_marker_, self.links_)
def test_instance_list_all_projects(self): instance_id = self.random_uuid() name = self.random_name('test-list') tenant_id = self.random_uuid() server_id = self.random_uuid() insts = [{ "id": instance_id, "name": name, "status": "ACTIVE", "operating_status": "HEALTHY", "addresses": [{ "type": "private", "address": "10.0.0.13" }], "volume": { "size": 2 }, "flavor": { "id": "02" }, "region": "regionOne", "datastore": { "version": "5.6", "type": "mysql", "version_number": "5.7.29" }, "tenant_id": tenant_id, "access": { "is_public": False, "allowed_cidrs": [] }, "server_id": server_id, 'server': { 'id': server_id } }] self.mgmt_client.list.return_value = common.Paginated( [instances.Instance(mock.MagicMock(), inst) for inst in insts]) parsed_args = self.check_parser(self.cmd, ["--all-projects"], [("all_projects", True)]) columns, data = self.cmd.take_action(parsed_args) self.mgmt_client.list.assert_called_once_with(**self.defaults) self.assertEqual( database_instances.ListDatabaseInstances.admin_columns, columns) expected_instances = [ (instance_id, name, 'mysql', '5.6', 'ACTIVE', 'HEALTHY', False, [{ "type": "private", "address": "10.0.0.13" }], '02', 2, '', server_id, tenant_id), ] self.assertEqual(expected_instances, data)
def test_index(self): clusters = common.Paginated(self.trove_clusters.list()) self.mock_cluster_list.return_value = clusters self.mock_flavor_list.return_value = self.flavors.list() res = self.client.get(INDEX_URL) self.mock_cluster_list.assert_called_once_with(test.IsHttpRequest(), marker=None) self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest()) self.assertTemplateUsed(res, 'project/database_clusters/index.html')
def test_index(self): clusters = common.Paginated(self.trove_clusters.list()) trove_api.trove.cluster_list(IsA(http.HttpRequest), marker=None)\ .AndReturn(clusters) trove_api.trove.flavor_list(IsA(http.HttpRequest))\ .AndReturn(self.flavors.list()) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'project/database_clusters/index.html')
def test_index_flavor_exception(self): clusters = common.Paginated(self.trove_clusters.list()) self.mock_cluster_list.return_value = clusters self.mock_flavor_list.side_effect = self.exceptions.trove res = self.client.get(INDEX_URL) self.mock_cluster_list.assert_called_once_with(test.IsHttpRequest(), marker=None) self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest()) self.assertTemplateUsed(res, 'project/database_clusters/index.html') self.assertMessageCount(res, error=1)
def test_index(self): # Mock database instances databases = common.Paginated(self.databases.list()) api.trove.instance_list(IsA(http.HttpRequest), marker=None)\ .AndReturn(databases) # Mock flavors api.trove.flavor_list(IsA(http.HttpRequest))\ .AndReturn(self.flavors.list()) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'project/databases/index.html')
def test_restore_backup(self): policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True) backup = self.database_backups.first() api.trove.backup_get(IsA(http.HttpRequest), IsA(six.text_type)) \ .AndReturn(self.database_backups.first()) api.trove.backup_list(IsA(http.HttpRequest)).AndReturn( self.database_backups.list()) api.trove.configuration_list(IsA(http.HttpRequest)) \ .AndReturn(self.database_configurations.list()) api.trove.datastore_flavors(IsA(http.HttpRequest), IsA(six.string_types), IsA(six.string_types)) \ .AndReturn(self.flavors.list()) api.trove.datastore_list(IsA(http.HttpRequest)) \ .AndReturn(self.datastores.list()) api.trove.datastore_version_list(IsA(http.HttpRequest), backup.datastore['type']) \ .AndReturn(self.datastore_versions.list()) api.trove.instance_list(IsA(http.HttpRequest), marker=None) \ .AndReturn(common.Paginated(self.databases.list())) dash_api.cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn([]) dash_api.neutron.network_list(IsA(http.HttpRequest), tenant_id=self.tenant.id, shared=False).\ AndReturn(self.networks.list()[:1]) dash_api.nova.availability_zone_list(IsA(http.HttpRequest)) \ .AndReturn(self.availability_zones.list()) self.mox.ReplayAll() url = RESTORE_URL + '?backup=%s' % self.database_backups.first().id res = self.client.get(url) self.assertTemplateUsed(res, 'project/databases/launch.html') set_instance_detail_step = \ [step for step in res.context_data['workflow'].steps if isinstance(step, create_instance.SetInstanceDetails)][0] fields = set_instance_detail_step.action.fields self.assertTrue(len(fields['datastore'].choices), 1) text = 'mysql - 5.6' choice = fields['datastore'].choices[0] self.assertTrue(choice[0], common_utils.hexlify(text)) self.assertTrue(choice[1], text) advanced_step = [ step for step in res.context_data['workflow'].steps if isinstance(step, create_instance.Advanced) ][0] fields = advanced_step.action.fields self.assertTrue(len(fields['initial_state'].choices), 1) choice = fields['initial_state'].choices[0] self.assertTrue(choice[0], 'backup') self.assertTrue(choice[1], _('Restore from Backup'))
def test_index_pagination(self): # Mock database instances databases = common.Paginated(self.databases.list(), next_marker="foo") api.trove.instance_list(IsA(http.HttpRequest), marker=None)\ .AndReturn(databases) # Mock flavors api.trove.flavor_list(IsA(http.HttpRequest))\ .AndReturn(self.flavors.list()) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'project/databases/index.html') self.assertContains(res, 'marker=6ddc36d9-73db-4e23-b52e-368937d72719')
def test_index_pagination(self): clusters = self.trove_clusters.list() last_record = clusters[1] clusters = common.Paginated(clusters, next_marker="foo") trove_api.trove.cluster_list(IsA(http.HttpRequest), marker=None)\ .AndReturn(clusters) trove_api.trove.flavor_list(IsA(http.HttpRequest))\ .AndReturn(self.flavors.list()) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'project/database_clusters/index.html') self.assertContains(res, 'marker=' + last_record.id)
def test_index_pagination(self): clusters = self.trove_clusters.list() last_record = clusters[1] clusters = common.Paginated(clusters, next_marker="foo") self.mock_cluster_list.return_value = clusters self.mock_flavor_list.return_value = self.flavors.list() res = self.client.get(INDEX_URL) self.mock_cluster_list.assert_called_once_with(test.IsHttpRequest(), marker=None) self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest()) self.assertTemplateUsed(res, 'project/database_clusters/index.html') self.assertContains(res, 'marker=' + last_record.id)
def _paginated(self, url, response_key, limit=None, marker=None): resp, body = self.api.client.get(common.limit_url(url, limit, marker)) if not body: raise Exception("Call to " + url + " did not return a body.") links = body.get('links', []) next_links = [link['href'] for link in links if link['rel'] == 'next'] next_marker = None for link in next_links: # Extract the marker from the url. parsed_url = parse.urlparse(link) query_dict = dict(parse.parse_qsl(parsed_url.query)) next_marker = query_dict.get('marker') data = [self.resource_class(self, res) for res in body[response_key]] return common.Paginated(data, next_marker=next_marker, links=links)
def test_instance_list_defaults(self): self.instance_client.list.return_value = common.Paginated(self.data) parsed_args = self.check_parser(self.cmd, [], []) columns, data = self.cmd.take_action(parsed_args) self.instance_client.list.assert_called_once_with(**self.defaults) self.assertEqual(database_instances.ListDatabaseInstances.columns, columns) values = [('1234', 'test-member-1', 'mysql', '5.6', 'ACTIVE', '10.0.0.13', '02', 2, 'regionOne'), ('5678', 'test-member-2', 'mysql', '5.6', 'ACTIVE', '10.0.0.14', '2', 2, 'regionOne')] self.assertEqual(values, data)
def test_index(self): # Mock database instances databases = common.Paginated(self.databases.list()) api.trove.instance_list(IsA(http.HttpRequest), marker=None)\ .AndReturn(databases) # Mock flavors api.trove.flavor_list(IsA(http.HttpRequest))\ .AndReturn(self.flavors.list()) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'project/databases/index.html') # Check the Host column displaying ip or hostname self.assertContains(res, '10.0.0.3') self.assertContains(res, 'trove.instance-2.com')
def test_index_flavor_list_exception(self): #Mocking instances databases = common.Paginated(self.databases.list()) api.trove.instance_list(IsA(http.HttpRequest), marker=None)\ .AndReturn(databases) #Mocking flavor list with raising an exception api.trove.flavor_list(IsA(http.HttpRequest))\ .AndRaise(self.exceptions.trove) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'project/databases/index.html') self.assertMessageCount(res, error=1)
def test_index_pagination(self): # Mock database instances databases = self.databases.list() last_record = databases[1] databases = common.Paginated(databases, next_marker="foo") api.trove.instance_list(IsA(http.HttpRequest), marker=None)\ .AndReturn(databases) # Mock flavors api.trove.flavor_list(IsA(http.HttpRequest))\ .AndReturn(self.flavors.list()) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'project/databases/index.html') self.assertContains(res, 'marker=' + last_record.id)
def test_instance_list_all_projects(self): self.mgmt_client.list.return_value = common.Paginated(self.data) parsed_args = self.check_parser(self.cmd, ["--all-projects"], [("all_projects", True)]) columns, instances = self.cmd.take_action(parsed_args) self.mgmt_client.list.assert_called_once_with(**self.defaults) self.assertEqual( database_instances.ListDatabaseInstances.admin_columns, columns) expected_instances = [('1234', 'test-member-1', 'fake_tenant_id', 'mysql', '5.6', 'ACTIVE', '10.0.0.13', '02', 2), ('5678', 'test-member-2', 'fake_tenant_id', 'mysql', '5.6', 'ACTIVE', '10.0.0.14', '2', 2)] self.assertEqual(expected_instances, instances)
def setUp(self): super(TestConfigurationList, self).setUp() self.cmd = database_configurations.ListDatabaseConfigurations(self.app, None) data = [self.fake_configurations.get_configurations_c_123()] self.configuration_client.list.return_value = common.Paginated(data)
def setUp(self): super(TestClusterList, self).setUp() self.cmd = database_clusters.ListDatabaseClusters(self.app, None) data = [self.fake_clusters.get_clusters_cls_1234()] self.cluster_client.list.return_value = common.Paginated(data)
def setUp(self): super(TestBackupList, self).setUp() self.cmd = database_backups.ListDatabaseBackups(self.app, None) data = [self.fake_backups.get_backup_bk_1234()] self.backup_client.list.return_value = common.Paginated(data)
def setUp(self): super(TestDatabaseList, self).setUp() self.cmd = databases.ListDatabases(self.app, None) data = [self.fake_databases.get_databases_1()] self.database_client.list.return_value = common.Paginated(data)
def setUp(self): super(TestLimitList, self).setUp() self.cmd = database_limits.ListDatabaseLimits(self.app, None) data = [self.fake_limits.get_absolute_limits(), self.fake_limits.get_non_absolute_limits()] self.limit_client.list.return_value = common.Paginated(data)
def setUp(self): super(TestInstanceList, self).setUp() self.cmd = database_instances.ListDatabaseInstances(self.app, None) self.data = self.fake_instances.get_instances() self.instance_client.list.return_value = common.Paginated(self.data)
def setUp(self): super(TestDatastoreVersionList, self).setUp() self.cmd = datastores.ListDatastoreVersions(self.app, None) self.data = [self.fake_datastores.get_datastores_d_123_versions()] self.datastore_version_client.list.return_value =\ common.Paginated(self.data)
def test_restore_backup(self): backup = self.database_backups.first() self.mock_check.return_value = True self.mock_backup_get.return_value = self.database_backups.first() self.mock_backup_list.return_value = self.database_backups.list() self.mock_configuration_list.return_value = ( self.database_configurations.list()) self.mock_datastore_flavors.return_value = self.flavors.list() self.mock_datastore_list.return_value = self.datastores.list() self.mock_datastore_version_list.return_value = ( self.datastore_versions.list()) self.mock_instance_list.return_value = (common.Paginated( self.databases.list())) self.mock_volume_type_list.return_vlue = [] self.mock_network_list_for_tenant.return_value = ( self.networks.list()[:1]) self.mock_availability_zone_list.return_value = ( self.availability_zones.list()) url = RESTORE_URL + '?backup=%s' % self.database_backups.first().id res = self.client.get(url) self.assert_mock_multiple_calls_with_same_arguments( self.mock_check, 5, mock.call((), test.IsHttpRequest())) self.mock_backup_get.assert_called_once_with(test.IsHttpRequest(), test.IsA(str)) self.mock_backup_list.assert_called_once_with(test.IsHttpRequest()) self.mock_configuration_list.assert_called_once_with( test.IsHttpRequest()) self.mock_datastore_flavors.assert_called_once_with( test.IsHttpRequest(), test.IsA(str), test.IsA(str)) self.mock_datastore_list.assert_called_once_with(test.IsHttpRequest()) self.mock_datastore_version_list.assert_called_once_with( test.IsHttpRequest(), backup.datastore['type']) self.mock_instance_list.assert_called_once_with(test.IsHttpRequest()) self.mock_volume_type_list.assert_called_once_with( test.IsHttpRequest()) self.mock_network_list_for_tenant.assert_called_once_with( test.IsHttpRequest(), self.tenant.id, include_pre_auto_allocate=True) self.mock_availability_zone_list.assert_called_once_with( test.IsHttpRequest()) self.assertTemplateUsed(res, 'project/databases/launch.html') set_instance_detail_step = \ [step for step in res.context_data['workflow'].steps if isinstance(step, create_instance.SetInstanceDetails)][0] fields = set_instance_detail_step.action.fields self.assertTrue(len(fields['datastore'].choices), 1) text = 'mysql - 5.6' choice = fields['datastore'].choices[0] self.assertTrue(choice[0], common_utils.hexlify(text)) self.assertTrue(choice[1], text) advanced_step = [ step for step in res.context_data['workflow'].steps if isinstance(step, create_instance.Advanced) ][0] fields = advanced_step.action.fields self.assertTrue(len(fields['initial_state'].choices), 1) choice = fields['initial_state'].choices[0] self.assertTrue(choice[0], 'backup') self.assertTrue(choice[1], _('Restore from Backup'))
def setUp(self): super(TestUserList, self).setUp() self.cmd = database_users.ListDatabaseUsers(self.app, None) data = [self.fake_users.get_instances_1234_users_harry()] self.user_client.list.return_value = common.Paginated(data)