def test_validate(self):
     connection_info = objects.ConsoleAuthToken.validate(
         self.context, self.token)
     expected = self.console.obj_to_primitive()['nova_object.data']
     del expected['created_at']
     ovo_fixture.compare_obj(self, connection_info, expected,
                             allow_missing=['created_at'])
 def test_get_by_project_id(self):
     create_group = self._api_group()
     get_groups = objects.InstanceGroupList.get_by_project_id(
         self.context, self.context.project_id)
     self.assertEqual(1, len(get_groups))
     self.assertTrue(base.obj_equal_prims(create_group, get_groups[0]))
     ovo_fixture.compare_obj(self, get_groups[0], create_group)
Exemplo n.º 3
0
 def test_get_all(self):
     create_group = self._api_group()
     db_group = self._main_group()
     get_groups = objects.InstanceGroupList.get_all(self.context)
     self.assertEqual(2, len(get_groups))
     self.assertTrue(base.obj_equal_prims(create_group, get_groups[0]))
     ovo_fixture.compare_obj(self, get_groups[1], db_group)
Exemplo n.º 4
0
 def test_get_by_project_id(self):
     create_group = self._api_group()
     get_groups = objects.InstanceGroupList.get_by_project_id(
             self.context, self.context.project_id)
     self.assertEqual(1, len(get_groups))
     self.assertTrue(base.obj_equal_prims(create_group, get_groups[0]))
     ovo_fixture.compare_obj(self, get_groups[0], create_group)
Exemplo n.º 5
0
 def test_validate(self):
     connection_info = objects.ConsoleAuthToken.validate(
         self.context, self.token)
     expected = self.console.obj_to_primitive()['nova_object.data']
     del expected['created_at']
     ovo_fixture.compare_obj(self, connection_info, expected,
                             allow_missing=['created_at'])
Exemplo n.º 6
0
 def test_get(self):
     self.mox.StubOutWithMock(db, 'security_group_get')
     db.security_group_get(self.context, 1).AndReturn(fake_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup.get(self.context, 1)
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(fake_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
Exemplo n.º 7
0
    def test_compare_obj_with_unset_in_db_dict_ignored(self):
        # If the object has something set, but the db dict doesn't, but we
        # ignore that key, we are equal
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1}
        ignore = ['bar']

        fixture.compare_obj(self, my_obj, my_db_obj, allow_missing=ignore)
    def test_compare_obj_with_unset_in_db_dict_ignored(self):
        # If the object has something set, but the db dict doesn't, but we
        # ignore that key, we are equal
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1}
        ignore = ['bar']

        fixture.compare_obj(self, my_obj, my_db_obj, allow_missing=ignore)
Exemplo n.º 9
0
 def test_create(self):
     create_group = self._api_group()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                  create_group.uuid)
     ovo_fixture.compare_obj(self,
                             create_group,
                             db_group,
                             allow_missing=('deleted', 'deleted_at'))
Exemplo n.º 10
0
 def test_get_by_name(self, mock_get):
     secgroup = security_group.SecurityGroup.get_by_name(
         self.context, 'fake-project', 'fake-name')
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(fake_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
     mock_get.assert_called_once_with(self.context, 'fake-project',
                                      'fake-name')
Exemplo n.º 11
0
 def test_get(self):
     self.mox.StubOutWithMock(db, 'security_group_get')
     db.security_group_get(self.context, 1).AndReturn(fake_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup.get(self.context, 1)
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(fake_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
Exemplo n.º 12
0
 def test_get_by_name(self, mock_get):
     secgroup = security_group.SecurityGroup.get_by_name(self.context,
                                                         'fake-project',
                                                         'fake-name')
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(fake_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
     mock_get.assert_called_once_with(self.context,
                                      'fake-project',
                                      'fake-name')
Exemplo n.º 13
0
 def test_save_main(self, _mock_notify):
     db_group = self._main_group()
     create_group = objects.InstanceGroup._from_db_object(
             self.context, objects.InstanceGroup(), db_group)
     create_group.policies = ['bar1', 'bar2']
     create_group.members = ['memberbar1', 'memberbar2']
     create_group.name = 'anewname'
     create_group.save()
     db_group = db_api.instance_group_get(self.context, create_group.uuid)
     ovo_fixture.compare_obj(self, create_group, db_group)
Exemplo n.º 14
0
 def test_save(self, _mock_notify):
     create_group = self._api_group()
     create_group.policies = ['bar1', 'bar2']
     create_group.members = ['memberbar1', 'memberbar2']
     create_group.name = 'anewname'
     create_group.save()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                  create_group.uuid)
     ovo_fixture.compare_obj(self, create_group, db_group,
                             allow_missing=('deleted', 'deleted_at'))
Exemplo n.º 15
0
 def test_refresh(self, mock_get):
     updated_secgroup = dict(fake_secgroup, description='changed')
     mock_get.return_value = updated_secgroup
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(self.context),
         fake_secgroup)
     secgroup.refresh()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
     mock_get.assert_called_once_with(self.context, 1)
Exemplo n.º 16
0
    def test_compare_obj_with_dt(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        dt = datetime.datetime(1955, 11, 5, tzinfo=iso8601.iso8601.UTC)
        replaced_dt = dt.replace(tzinfo=None)
        my_obj = self.MyComparedObjectWithTZ(tzfield=dt)
        my_db_obj = {'tzfield': replaced_dt}

        fixture.compare_obj(mock_test, my_obj, my_db_obj)

        mock_test.assertEqual.assert_called_once_with(replaced_dt, replaced_dt)
    def test_compare_obj_with_allow_missing(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject(foo=1)
        my_db_obj = {'foo': 1, 'bar': 2}
        ignores = ['bar']

        fixture.compare_obj(mock_test, my_obj, my_db_obj,
                            allow_missing=ignores)

        mock_test.assertEqual.assert_called_once_with(1, 1)
Exemplo n.º 18
0
 def test_refresh(self, mock_get):
     updated_secgroup = dict(fake_secgroup, description='changed')
     mock_get.return_value = updated_secgroup
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(self.context),
         fake_secgroup)
     secgroup.refresh()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
     mock_get.assert_called_once_with(self.context, 1)
Exemplo n.º 19
0
 def test_save(self, _mock_notify):
     create_group = self._api_group()
     create_group.members = ['memberbar1', 'memberbar2']
     create_group.name = 'anewname'
     create_group.save()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                  create_group.uuid)
     ovo_fixture.compare_obj(
         self, create_group, db_group,
         comparators={'policy': lambda a, b: b == a.policy},
         allow_missing=('deleted', 'deleted_at', 'policies', '_rules'))
     self.assertEqual({'max_server_per_host': 1}, create_group.rules)
Exemplo n.º 20
0
 def test_create(self):
     create_group = self._api_group()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                  create_group.uuid)
     self.assertIsInstance(db_group.policy, api_models.InstanceGroupPolicy)
     self.assertEqual(create_group.policies[0], db_group.policy.policy)
     self.assertEqual(create_group.id, db_group.policy.group_id)
     self.assertIsNone(db_group.policy.rules)
     ovo_fixture.compare_obj(self,
                             create_group,
                             db_group,
                             allow_missing=('deleted', 'deleted_at'))
Exemplo n.º 21
0
 def test_refresh(self):
     updated_secgroup = dict(fake_secgroup, description='changed')
     self.mox.StubOutWithMock(db, 'security_group_get')
     db.security_group_get(self.context, 1).AndReturn(updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(self.context),
         fake_secgroup)
     secgroup.refresh()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
    def test_compare_obj(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1, 'bar': 2}

        fixture.compare_obj(mock_test, my_obj, my_db_obj)

        expected_calls = [(1, 1), (2, 2)]
        actual_calls = [c[0] for c in mock_test.assertEqual.call_args_list]
        for call in expected_calls:
            self.assertIn(call, actual_calls)
    def test_compare_obj_with_dt(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        dt = datetime.datetime(1955, 11, 5, tzinfo=iso8601.iso8601.Utc())
        replaced_dt = dt.replace(tzinfo=None)
        my_obj = self.MyComparedObjectWithTZ(tzfield=dt)
        my_db_obj = {'tzfield': replaced_dt}

        fixture.compare_obj(mock_test, my_obj, my_db_obj)

        mock_test.assertEqual.assert_called_once_with(replaced_dt,
                                                      replaced_dt)
Exemplo n.º 24
0
 def test_create(self):
     create_group = self._api_group()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                   create_group.uuid)
     self.assertIsInstance(db_group.policy, api_models.InstanceGroupPolicy)
     self.assertEqual(create_group.policies[0], db_group.policy.policy)
     self.assertEqual(create_group.id, db_group.policy.group_id)
     ovo_fixture.compare_obj(
         self, create_group, db_group,
         comparators={'policy': lambda a, b: b == a.policy},
         allow_missing=('deleted', 'deleted_at', 'policies', '_rules'))
     self.assertEqual({'max_server_per_host': 1}, create_group.rules)
    def test_compare_obj_with_unset(self):
        # If the object has nothing set, and also the db object has the same
        # thing not set, it's OK.
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject()
        my_db_obj = {}

        fixture.compare_obj(mock_test, my_obj, my_db_obj)

        self.assertFalse(mock_test.assertEqual.called, "assertEqual should "
                         "not have been called, there is nothing to compare.")
Exemplo n.º 26
0
 def test_refresh(self):
     updated_secgroup = dict(fake_secgroup, description='changed')
     self.mox.StubOutWithMock(db, 'security_group_get')
     db.security_group_get(self.context, 1).AndReturn(updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(self.context),
         fake_secgroup)
     secgroup.refresh()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
Exemplo n.º 27
0
    def test_compare_obj(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1, 'bar': 2}

        fixture.compare_obj(mock_test, my_obj, my_db_obj)

        expected_calls = [(1, 1), (2, 2)]
        actual_calls = [c[0] for c in mock_test.assertEqual.call_args_list]
        for call in expected_calls:
            self.assertIn(call, actual_calls)
Exemplo n.º 28
0
 def test_save(self, mock_update):
     updated_secgroup = dict(fake_secgroup, project_id='changed')
     mock_update.return_value = updated_secgroup
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(), fake_secgroup)
     secgroup.description = 'foobar'
     secgroup.save()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
     mock_update.assert_called_once_with(self.context, 1,
                                         {'description': 'foobar'})
Exemplo n.º 29
0
 def test_save(self, mock_update):
     updated_secgroup = dict(fake_secgroup, project_id='changed')
     mock_update.return_value = updated_secgroup
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(),
         fake_secgroup)
     secgroup.description = 'foobar'
     secgroup.save()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
     mock_update.assert_called_once_with(self.context, 1,
                                         {'description': 'foobar'})
Exemplo n.º 30
0
    def test_compare_obj_with_allow_missing(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject(foo=1)
        my_db_obj = {'foo': 1, 'bar': 2}
        ignores = ['bar']

        fixture.compare_obj(mock_test,
                            my_obj,
                            my_db_obj,
                            allow_missing=ignores)

        mock_test.assertEqual.assert_called_once_with(1, 1)
    def test_compare_obj_with_comparators(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        comparator = mock.Mock()
        comp_dict = {'foo': comparator}
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1, 'bar': 2}

        fixture.compare_obj(mock_test, my_obj, my_db_obj,
                            comparators=comp_dict)

        comparator.assert_called_once_with(1, 1)
        mock_test.assertEqual.assert_called_once_with(2, 2)
Exemplo n.º 32
0
    def test_compare_obj_with_unset(self):
        # If the object has nothing set, and also the db object has the same
        # thing not set, it's OK.
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject()
        my_db_obj = {}

        fixture.compare_obj(mock_test, my_obj, my_db_obj)

        self.assertFalse(
            mock_test.assertEqual.called, "assertEqual should "
            "not have been called, there is nothing to compare.")
Exemplo n.º 33
0
 def test_save(self):
     self.mox.StubOutWithMock(db, 'security_group_update')
     updated_secgroup = dict(fake_secgroup, project_id='changed')
     db.security_group_update(self.context, 1, {
         'description': 'foobar'
     }).AndReturn(updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(), fake_secgroup)
     secgroup.description = 'foobar'
     secgroup.save()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
Exemplo n.º 34
0
    def test_compare_obj_with_allow_missing_unequal(self):
        # If the tested key is in allow_missing, but both the obj and db_obj
        # have the value set, we should still check it for equality
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1, 'bar': 1}
        ignore = ['bar']

        fixture.compare_obj(mock_test, my_obj, my_db_obj, allow_missing=ignore)

        expected_calls = [(1, 1), (1, 2)]
        actual_calls = [c[0] for c in mock_test.assertEqual.call_args_list]
        for call in expected_calls:
            self.assertIn(call, actual_calls)
Exemplo n.º 35
0
    def test_compare_obj_with_comparators(self):
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        comparator = mock.Mock()
        comp_dict = {'foo': comparator}
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1, 'bar': 2}

        fixture.compare_obj(mock_test,
                            my_obj,
                            my_db_obj,
                            comparators=comp_dict)

        comparator.assert_called_once_with(1, 1)
        mock_test.assertEqual.assert_called_once_with(2, 2)
Exemplo n.º 36
0
 def test_save(self):
     self.mox.StubOutWithMock(db, 'security_group_update')
     updated_secgroup = dict(fake_secgroup, project_id='changed')
     db.security_group_update(self.context, 1,
                              {'description': 'foobar'}).AndReturn(
                                  updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(),
         fake_secgroup)
     secgroup.description = 'foobar'
     secgroup.save()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
Exemplo n.º 37
0
 def test_save(self, _mock_notify):
     create_group = self._api_group()
     create_group.members = ['memberbar1', 'memberbar2']
     create_group.name = 'anewname'
     create_group.save()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                  create_group.uuid)
     ovo_fixture.compare_obj(self,
                             create_group,
                             db_group,
                             comparators={
                                 'policy': lambda a, b: b == a.policy
                             },
                             allow_missing=('deleted', 'deleted_at',
                                            'policies', '_rules'))
     self.assertEqual({'max_server_per_host': 1}, create_group.rules)
Exemplo n.º 38
0
 def test_create(self):
     create_group = self._api_group()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                  create_group.uuid)
     self.assertIsInstance(db_group.policy, api_models.InstanceGroupPolicy)
     self.assertEqual(create_group.policies[0], db_group.policy.policy)
     self.assertEqual(create_group.id, db_group.policy.group_id)
     ovo_fixture.compare_obj(self,
                             create_group,
                             db_group,
                             comparators={
                                 'policy': lambda a, b: b == a.policy
                             },
                             allow_missing=('deleted', 'deleted_at',
                                            'policies', '_rules'))
     self.assertEqual({'max_server_per_host': 1}, create_group.rules)
    def test_compare_obj_with_allow_missing_unequal(self):
        # If the tested key is in allow_missing, but both the obj and db_obj
        # have the value set, we should still check it for equality
        mock_test = mock.Mock()
        mock_test.assertEqual = mock.Mock()
        my_obj = self.MyComparedObject(foo=1, bar=2)
        my_db_obj = {'foo': 1, 'bar': 1}
        ignore = ['bar']

        fixture.compare_obj(mock_test, my_obj, my_db_obj,
                            allow_missing=ignore)

        expected_calls = [(1, 1), (1, 2)]
        actual_calls = [c[0] for c in mock_test.assertEqual.call_args_list]
        for call in expected_calls:
            self.assertIn(call, actual_calls)
Exemplo n.º 40
0
 def test_create(self):
     create_group = self._api_group()
     db_group = create_group._get_from_db_by_uuid(self.context,
                                                   create_group.uuid)
     ovo_fixture.compare_obj(self, create_group, db_group,
                             allow_missing=('deleted', 'deleted_at'))
Exemplo n.º 41
0
 def test_get_by_name_main(self):
     db_group = self._main_group()
     get_group = objects.InstanceGroup.get_by_name(self.context,
                                                   db_group.name)
     ovo_fixture.compare_obj(self, get_group, db_group)
Exemplo n.º 42
0
 def test_get_by_instance_uuid_main(self):
     db_group = self._main_group(members=[uuids.instance])
     get_group = objects.InstanceGroup.get_by_instance_uuid(self.context,
                                                            uuids.instance)
     ovo_fixture.compare_obj(self, get_group, db_group)