def test_aggregate_host_add_to_db(self):
     result = _create_aggregate(self.context, metadata=None)
     host = _get_fake_hosts(1)[0]
     aggregate_obj._host_add_to_db(self.context, result['id'], host)
     expected = aggregate_obj._aggregate_get_from_db(self.context,
                                                     result['id'])
     self.assertEqual([_get_fake_hosts(1)[0]], expected.hosts)
 def test_aggregate_remove_availability_zone(self):
     result = _create_aggregate(self.context, metadata={'availability_zone':
         'fake_avail_zone'})
     aggregate_obj._metadata_delete_from_db(self.context,
                                        result['id'],
                                        'availability_zone')
     aggr = aggregate_obj._aggregate_get_from_db(self.context, result['id'])
     self.assertIsNone(aggr['availability_zone'])
Beispiel #3
0
 def test_aggregate_create_in_db(self):
     fake_create_aggregate = {
         'name': 'fake-aggregate',
     }
     agg = aggregate_obj._aggregate_create_in_db(self.context,
                                                 fake_create_aggregate)
     result = aggregate_obj._aggregate_get_from_db(self.context,
                                                   agg.id)
     self.assertEqual(result.name, fake_create_aggregate['name'])
Beispiel #4
0
 def test_aggregate_update(self):
     created = _create_aggregate(self.context,
                         metadata={'availability_zone': 'fake_avail_zone'})
     result = aggregate_obj._aggregate_get_from_db(self.context,
                                                   created['id'])
     self.assertEqual('fake_avail_zone', result['availability_zone'])
     new_values = deepcopy(_get_fake_aggregate(1, result=False))
     new_values['availability_zone'] = 'different_avail_zone'
     updated = aggregate_obj._aggregate_update_to_db(self.context,
                                                 result['id'], new_values)
     self.assertEqual('different_avail_zone', updated['availability_zone'])
Beispiel #5
0
 def test_aggregate_create_in_db_with_metadata(self):
     fake_create_aggregate = {
         'name': 'fake-aggregate',
     }
     agg = aggregate_obj._aggregate_create_in_db(self.context,
                                             fake_create_aggregate,
                                             metadata={'goodkey': 'good'})
     result = aggregate_obj._aggregate_get_from_db(self.context,
                                                   agg.id)
     md = aggregate_obj._get_by_metadata_key_from_db(self.context,
                                                     key='goodkey')
     self.assertEqual(len(md), 1)
     self.assertEqual(md[0]['id'], agg.id)
     self.assertEqual(result.name, fake_create_aggregate['name'])
Beispiel #6
0
 def test_aggregate_update_with_metadata(self):
     result = _create_aggregate(self.context, metadata=None)
     values = deepcopy(_get_fake_aggregate(1, result=False))
     values['metadata'] = deepcopy(_get_fake_metadata(1))
     values['availability_zone'] = 'different_avail_zone'
     expected_metadata = deepcopy(values['metadata'])
     expected_metadata['availability_zone'] = values['availability_zone']
     aggregate_obj._aggregate_update_to_db(self.context, result['id'],
                                           values)
     metadata = _aggregate_metadata_get_all(self.context, result['id'])
     updated = aggregate_obj._aggregate_get_from_db(self.context,
                                                    result['id'])
     self.assertThat(metadata,
                     matchers.DictMatches(expected_metadata))
     self.assertEqual('different_avail_zone', updated['availability_zone'])
Beispiel #7
0
 def test_aggregate_get_from_db(self):
     result = _create_aggregate_with_hosts(self.context)
     expected = aggregate._aggregate_get_from_db(self.context, result['id'])
     self.assertEqual(fake_db_aggregate_hosts, expected.hosts)
     self.assertEqual(fake_db_aggregate_metadata, expected['metadetails'])
Beispiel #8
0
 def test_aggregate_get_from_db(self):
     result = _create_aggregate_with_hosts(self.context)
     expected = aggregate_obj._aggregate_get_from_db(
         self.context, result['id'])
     self.assertEqual(_get_fake_hosts(1), expected.hosts)
     self.assertEqual(_get_fake_metadata(1), expected['metadetails'])