def test_not_equal(self): # Setup res_cat_1 = models.OvercloudRole(name='foo') res_cat_2 = models.OvercloudRole(name='bar') # Test self.assertTrue(res_cat_1 != res_cat_2)
def test_parse_counts_overcloud_roles_explicit(self): # Setup overcloud_role_1 = db_models.OvercloudRole( image_name='overcloud-compute', flavor_id='1') overcloud_role_2 = db_models.OvercloudRole( image_name='overcloud-cinder-volume', flavor_id='1') mock_overcloud_roles = {1: overcloud_role_1, 2: overcloud_role_2} overcloud_role_count_1 = db_models.OvercloudRoleCount( overcloud_role_id=1, num_nodes=5) overcloud_role_count_2 = db_models.OvercloudRoleCount( overcloud_role_id=2, num_nodes=9) mock_counts = [overcloud_role_count_1, overcloud_role_count_2] # Test result = overcloud.parse_counts_and_flavors( mock_counts, overcloud_roles=mock_overcloud_roles) # Verify self.assertEqual(result, ({'overcloud-compute': 5, 'overcloud-cinder-volume': 9}, {'overcloud-compute': '1', 'overcloud-cinder-volume': '1'}))
def test_update_overcloud_counts(self): # Setup # Roles role_2 = self.connection.create_overcloud_role( models.OvercloudRole(name='name-2', )) role_3 = self.connection.create_overcloud_role( models.OvercloudRole(name='name-3', )) role_4 = self.connection.create_overcloud_role( models.OvercloudRole(name='name-4', )) # Add extra counts for enough data self.overcloud_1.counts.append( models.OvercloudRoleCount( overcloud_role_id=role_2.id, num_nodes=2, )) self.overcloud_1.counts.append( models.OvercloudRoleCount( overcloud_role_id=role_3.id, num_nodes=3, )) saved = self.connection.create_overcloud(self.overcloud_1) # Test # - Ignore the first saved.counts.pop(0) # - Change the second saved.counts[0].num_nodes = 100 # - Delete the third saved.counts[1].num_nodes = 0 # - Add a fourth saved.counts.append( models.OvercloudRoleCount( overcloud_role_id=role_4.id, num_nodes=4, )) self.connection.update_overcloud(saved) # Verify found = self.connection.get_overcloud_by_id(saved.id) self.assertEqual(3, len(found.counts)) self.assertEqual(found.counts[0].overcloud_role_id, self.saved_role.id) self.assertEqual(found.counts[0].num_nodes, 4) self.assertEqual(found.counts[1].overcloud_role_id, role_2.id) self.assertEqual(found.counts[1].num_nodes, 100) self.assertEqual(found.counts[2].overcloud_role_id, role_4.id) self.assertEqual(found.counts[2].num_nodes, 4)
def test_put(self, mock_db_update, mock_process_stack): # Setup changes = {'name': 'updated'} overcloud_role_1 = db_models.OvercloudRole( image_name='overcloud-compute', flavor_id='1') overcloud_role_2 = db_models.OvercloudRole( image_name='overcloud-cinder-volume', flavor_id='1') overcloud_role_count_1 = db_models.OvercloudRoleCount( overcloud_role_id=1, num_nodes=5, overcloud_role=overcloud_role_1) overcloud_role_count_2 = db_models.OvercloudRoleCount( overcloud_role_id=2, num_nodes=9, overcloud_role=overcloud_role_2) attribute_1 = db_models.OvercloudAttribute( overcloud_id=1, key='name', value='updated') fake_updated = db_models.Overcloud(name='after-update', attributes=[attribute_1], counts=[overcloud_role_count_1, overcloud_role_count_2]) mock_db_update.return_value = fake_updated mock_process_stack.return_value = None # Test url = URL_OVERCLOUDS + '/' + '12345' response = self.app.put_json(url, params=changes) result = response.json # Verify self.assertEqual(response.status_int, 200) self.assertEqual(result['name'], fake_updated.name) self.assertEqual(1, mock_db_update.call_count) db_update_model = mock_db_update.call_args[0][0] self.assertTrue(isinstance(db_update_model, db_models.Overcloud)) self.assertEqual(db_update_model.id, 12345) self.assertEqual(db_update_model.name, changes['name']) mock_process_stack.assert_called_once_with( {'name': 'updated'}, [overcloud_role_count_1, overcloud_role_count_2], {})
def setUp(self): super(OvercloudRoleTests, self).setUp() self.connection = dbapi.Connection() self.save_me_1 = models.OvercloudRole( name='name-1', description='desc-1', image_name='image-1', flavor_id='tuvwxyz', ) self.save_me_2 = models.OvercloudRole( name='name-2', description='desc-2', image_name='image-2', flavor_id='abc', )
def test_create_overcloud_role_duplicate_name(self): # Setup self.connection.create_overcloud_role(self.save_me_1) duplicate = models.OvercloudRole(name=self.save_me_1.name, description='irrelevant', image_name='irrelevant') # Test self.assertRaises(exception.OvercloudRoleExists, self.connection.create_overcloud_role, duplicate)
def test_update(self): # Setup saved = self.connection.create_overcloud_role(self.save_me_1) # Test delta = models.OvercloudRole(id=saved.id, image_name='abcdef', flavor_id='new-flavor') self.connection.update_overcloud_role(delta) # Verify found = self.connection.get_overcloud_role_by_id(saved.id) self.assertEqual(found.image_name, delta.image_name) self.assertEqual(found.flavor_id, delta.flavor_id)
def test_get_one(self, mock_db_get): # Setup fake_result = db_models.OvercloudRole(name='foo') mock_db_get.return_value = fake_result # Test url = URL_ROLES + '/' + '12345' response = self.app.get(url) result = response.json # Verify self.assertEqual(response.status_int, 200) self.assertEqual(result['name'], 'foo') mock_db_get.assert_called_once_with(12345)
def test_get_all(self, mock_db_get): # Setup fake_results = [db_models.OvercloudRole(name='foo')] mock_db_get.return_value = fake_results # Test response = self.app.get(URL_ROLES) result = response.json # Verify self.assertEqual(response.status_int, 200) self.assertTrue(isinstance(result, list)) self.assertEqual(1, len(result)) self.assertEqual(result[0]['name'], 'foo') mock_db_get.assert_called_once()
def test_post(self, mock_db_create): # Setup create_me = {'name': 'new'} fake_created = db_models.OvercloudRole(name='created') mock_db_create.return_value = fake_created # Test response = self.app.post_json(URL_ROLES, params=create_me) result = response.json # Verify self.assertEqual(response.status_int, 201) self.assertEqual(result['name'], fake_created.name) self.assertEqual(1, mock_db_create.call_count) db_create_model = mock_db_create.call_args[0][0] self.assertTrue(isinstance(db_create_model, db_models.OvercloudRole)) self.assertEqual(db_create_model.name, create_me['name'])
def test_put(self, mock_db_update): # Setup changes = {'name': 'updated'} fake_updated = db_models.OvercloudRole(name='after-update') mock_db_update.return_value = fake_updated # Test url = URL_ROLES + '/' + '12345' response = self.app.put_json(url, params=changes) result = response.json # Verify self.assertEqual(response.status_int, 200) self.assertEqual(result['name'], fake_updated.name) self.assertEqual(1, mock_db_update.call_count) db_update_model = mock_db_update.call_args[0][0] self.assertTrue(isinstance(db_update_model, db_models.OvercloudRole)) self.assertEqual(db_update_model.id, 12345) self.assertEqual(db_update_model.name, changes['name'])
def setUp(self): super(OvercloudTests, self).setUp() self.connection = dbapi.Connection() self.role_1 = models.OvercloudRole( name='name-1', description='desc-1', image_name='image-1', flavor_id='tuvwxyz', ) self.saved_role = self.connection.create_overcloud_role(self.role_1) self.attributes_1 = models.OvercloudAttribute( key='key-1', value='value-1', ) self.attributes_2 = models.OvercloudAttribute( key='key-2', value='value-2', ) self.count_1 = models.OvercloudRoleCount( overcloud_role_id=self.saved_role.id, num_nodes=4, ) self.overcloud_1 = models.Overcloud( name='overcloud-1', description='desc-1', attributes=[self.attributes_1, self.attributes_2], counts=[self.count_1]) self.overcloud_2 = models.Overcloud(name='overcloud-2', description='desc-2', attributes=[])