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_different_overcloud_same_role(self): # Setup count_1 = models.OvercloudRoleCount(overcloud_id='o1', overcloud_role_id='r1') count_2 = models.OvercloudRoleCount(overcloud_id='o2', overcloud_role_id='r1') # Test self.assertTrue(count_1 != count_2)
def test_equal(self): # Setup count_1 = models.OvercloudRoleCount(overcloud_id='o1', overcloud_role_id='r1') count_2 = models.OvercloudRoleCount(overcloud_id='o1', overcloud_role_id='r1') # Test self.assertTrue(count_1 == count_2)
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_from_db_model(self): # Setup db_attrs = [ db_models.OvercloudAttribute( id=10, overcloud_id=1, key='key-1', value='value-1', ), db_models.OvercloudAttribute( id=20, overcloud_id=1, key='key-2', value='value-2', ), ] db_counts = [ db_models.OvercloudRoleCount( id=100, overcloud_id=1, overcloud_role_id=5, num_nodes=5, ) ] db_model = db_models.Overcloud( id=1, stack_id='stack-1', name='name-1', description='desc-1', attributes=db_attrs, counts=db_counts, ) # Test api_model = api_models.Overcloud.from_db_model(db_model) # Verify self.assertTrue(api_model is not None) self.assertTrue(isinstance(api_model, api_models.Overcloud)) self.assertEqual(api_model.id, db_model.id) self.assertEqual(api_model.stack_id, db_model.stack_id) self.assertEqual(api_model.name, db_model.name) self.assertEqual(api_model.description, db_model.description) self.assertEqual(len(api_model.attributes), len(db_model.attributes)) self.assertTrue(isinstance(api_model.attributes, dict)) for d_attr in db_model.attributes: self.assertEqual(api_model.attributes[d_attr.key], d_attr.value) self.assertEqual(len(api_model.counts), len(db_model.counts)) for a_count, d_count in zip(api_model.counts, db_model.counts): self.assertTrue(isinstance(a_count, api_models.OvercloudRoleCount)) self.assertEqual(a_count.id, d_count.id) self.assertEqual(a_count.overcloud_role_id, d_count.overcloud_role_id) self.assertEqual(a_count.overcloud_id, d_count.overcloud_id) self.assertEqual(a_count.num_nodes, d_count.num_nodes)
def to_db_model(self, omit_unset=False, skip_fields=None): # General Data db_model = super(Overcloud, self).to_db_model( omit_unset=omit_unset, skip_fields=['attributes', 'counts']) # Attributes if self.attributes != wtypes.Unset: translated = [] for key, value in self.attributes.items(): translated.append(db_models.OvercloudAttribute( key=key, value=value, overcloud_id=self.id )) db_model.attributes = translated # Counts if self.counts != wtypes.Unset: translated = [] for count in self.counts: translated.append(db_models.OvercloudRoleCount( num_nodes=count.num_nodes, overcloud_role_id=count.overcloud_role_id, overcloud_id=self.id )) db_model.counts = translated return db_model
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(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=[])