コード例 #1
0
    def test_trusted_filter_update_cache(self, req_mock):
        oat_data = {
            "hosts": [{
                "host_name": "node1",
                "trust_lvl": "untrusted",
                "vtime": timeutils.isotime()
            }]
        }

        req_mock.return_value = requests.codes.OK, oat_data
        extra_specs = {'trust:trusted_host': 'untrusted'}
        filter_properties = {
            'context': mock.sentinel.ctx,
            'instance_type': {
                'memory_mb': 1024,
                'extra_specs': extra_specs
            }
        }
        host = fakes.FakeHostState('host1', 'node1', {})

        self.filt_cls.host_passes(host, filter_properties)  # Fill the caches

        req_mock.reset_mock()
        self.filt_cls.host_passes(host, filter_properties)
        self.assertFalse(req_mock.called)

        req_mock.reset_mock()

        timeutils.set_time_override(timeutils.utcnow())
        timeutils.advance_time_seconds(
            CONF.trusted_computing.attestation_auth_timeout + 80)
        self.filt_cls.host_passes(host, filter_properties)
        self.assertTrue(req_mock.called)

        timeutils.clear_time_override()
コード例 #2
0
    def test_trusted_filter_update_cache_timezone(self, req_mock):
        oat_data = {"hosts": [{"host_name": "node1",
                                    "trust_lvl": "untrusted",
                                    "vtime": "2012-09-09T05:10:40-04:00"}]}
        req_mock.return_value = requests.codes.OK, oat_data
        extra_specs = {'trust:trusted_host': 'untrusted'}
        filter_properties = {'context': mock.sentinel.ctx,
                             'instance_type': {'memory_mb': 1024,
                                               'extra_specs': extra_specs}}
        host = fakes.FakeHostState('host1', 'node1', {})

        timeutils.set_time_override(
            timeutils.normalize_time(
                timeutils.parse_isotime("2012-09-09T09:10:40Z")))

        self.filt_cls.host_passes(host, filter_properties)  # Fill the caches

        req_mock.reset_mock()
        self.filt_cls.host_passes(host, filter_properties)
        self.assertFalse(req_mock.called)

        req_mock.reset_mock()
        timeutils.advance_time_seconds(
            CONF.trusted_computing.attestation_auth_timeout - 10)
        self.filt_cls.host_passes(host, filter_properties)
        self.assertFalse(req_mock.called)

        timeutils.clear_time_override()
コード例 #3
0
ファイル: test_db_api.py プロジェクト: NewpTone/stacklab-nova
    def test_bw_usage_calls(self):
        ctxt = context.get_admin_context()
        now = timeutils.utcnow()
        timeutils.set_time_override(now)
        start_period = now - datetime.timedelta(seconds=10)
        uuid3_refreshed = now - datetime.timedelta(seconds=5)

        expected_bw_usages = [
            {
                "uuid": "fake_uuid1",
                "mac": "fake_mac1",
                "start_period": start_period,
                "bw_in": 100,
                "bw_out": 200,
                "last_refreshed": now,
            },
            {
                "uuid": "fake_uuid2",
                "mac": "fake_mac2",
                "start_period": start_period,
                "bw_in": 200,
                "bw_out": 300,
                "last_refreshed": now,
            },
            {
                "uuid": "fake_uuid3",
                "mac": "fake_mac3",
                "start_period": start_period,
                "bw_in": 400,
                "bw_out": 500,
                "last_refreshed": uuid3_refreshed,
            },
        ]

        def _compare(bw_usage, expected):
            for key, value in expected.items():
                self.assertEqual(bw_usage[key], value)

        bw_usages = db.bw_usage_get_by_uuids(ctxt, ["fake_uuid1", "fake_uuid2"], start_period)
        # No matches
        self.assertEqual(len(bw_usages), 0)

        # Add 3 entries
        db.bw_usage_update(ctxt, "fake_uuid1", "fake_mac1", start_period, 100, 200)
        db.bw_usage_update(ctxt, "fake_uuid2", "fake_mac2", start_period, 100, 200)
        # Test explicit refreshed time
        db.bw_usage_update(ctxt, "fake_uuid3", "fake_mac3", start_period, 400, 500, last_refreshed=uuid3_refreshed)
        # Update 2nd entry
        db.bw_usage_update(ctxt, "fake_uuid2", "fake_mac2", start_period, 200, 300)

        bw_usages = db.bw_usage_get_by_uuids(ctxt, ["fake_uuid1", "fake_uuid2", "fake_uuid3"], start_period)
        self.assertEqual(len(bw_usages), 3)
        _compare(bw_usages[0], expected_bw_usages[0])
        _compare(bw_usages[1], expected_bw_usages[1])
        _compare(bw_usages[2], expected_bw_usages[2])
        timeutils.clear_time_override()
コード例 #4
0
 def tearDown(self):
     super(InstanceUsageAuditLogTest, self).tearDown()
     timeutils.clear_time_override()
コード例 #5
0
 def tearDown(self):
     timeutils.clear_time_override()
     super(AuditPeriodTest, self).tearDown()
コード例 #6
0
ファイル: test_utils.py プロジェクト: ykwon8651/project-e
 def tearDown(self):
     timeutils.clear_time_override()
     super(AuditPeriodTest, self).tearDown()
コード例 #7
0
ファイル: test_host_manager.py プロジェクト: xww/nova-old
 def tearDown(self):
     timeutils.clear_time_override()
     super(HostManagerTestCase, self).tearDown()
コード例 #8
0
 def tearDown(self):
     super(ServicesJsonTest, self).tearDown()
     timeutils.clear_time_override()
コード例 #9
0
 def tearDown(self):
     """tearDown method for simple tenant usage."""
     super(SimpleTenantUsageSampleJsonTest, self).tearDown()
     timeutils.clear_time_override()
コード例 #10
0
ファイル: test_services.py プロジェクト: RibeiroAna/nova
 def tearDown(self):
     super(ServicesJsonTest, self).tearDown()
     timeutils.clear_time_override()
コード例 #11
0
ファイル: test_cells_weights.py プロジェクト: nkuacac/nova
 def tearDown(self):
     super(MuteWeigherTestClass, self).tearDown()
     timeutils.clear_time_override()
コード例 #12
0
ファイル: test_cells_weights.py プロジェクト: aneeshpu/nova
 def tearDown(self):
     super(MuteWeigherTestClass, self).tearDown()
     timeutils.clear_time_override()
コード例 #13
0
 def tearDown(self):
     timeutils.clear_time_override()
     super(HostManagerTestCase, self).tearDown()
コード例 #14
0
ファイル: test_db_api.py プロジェクト: mapleoin/nova
    def test_bw_usage_calls(self):
        ctxt = context.get_admin_context()
        now = timeutils.utcnow()
        timeutils.set_time_override(now)
        start_period = now - datetime.timedelta(seconds=10)
        uuid3_refreshed = now - datetime.timedelta(seconds=5)

        expected_bw_usages = [{'uuid': 'fake_uuid1',
                               'mac': 'fake_mac1',
                               'start_period': start_period,
                               'bw_in': 100,
                               'bw_out': 200,
                               'last_ctr_in': 12345,
                               'last_ctr_out': 67890,
                               'last_refreshed': now},
                              {'uuid': 'fake_uuid2',
                               'mac': 'fake_mac2',
                               'start_period': start_period,
                               'bw_in': 200,
                               'bw_out': 300,
                               'last_ctr_in': 22345,
                               'last_ctr_out': 77890,
                               'last_refreshed': now},
                              {'uuid': 'fake_uuid3',
                               'mac': 'fake_mac3',
                               'start_period': start_period,
                               'bw_in': 400,
                               'bw_out': 500,
                               'last_ctr_in': 32345,
                               'last_ctr_out': 87890,
                               'last_refreshed': uuid3_refreshed}]

        def _compare(bw_usage, expected):
            for key, value in expected.items():
                self.assertEqual(bw_usage[key], value)

        bw_usages = db.bw_usage_get_by_uuids(ctxt,
                ['fake_uuid1', 'fake_uuid2'], start_period)
        # No matches
        self.assertEqual(len(bw_usages), 0)

        # Add 3 entries
        db.bw_usage_update(ctxt, 'fake_uuid1',
                'fake_mac1', start_period,
                100, 200, 12345, 67890)
        db.bw_usage_update(ctxt, 'fake_uuid2',
                'fake_mac2', start_period,
                100, 200, 42, 42)
        # Test explicit refreshed time
        db.bw_usage_update(ctxt, 'fake_uuid3',
                'fake_mac3', start_period,
                400, 500, 32345, 87890,
                last_refreshed=uuid3_refreshed)
        # Update 2nd entry
        db.bw_usage_update(ctxt, 'fake_uuid2',
                'fake_mac2', start_period,
                200, 300, 22345, 77890)

        bw_usages = db.bw_usage_get_by_uuids(ctxt,
                ['fake_uuid1', 'fake_uuid2', 'fake_uuid3'], start_period)
        self.assertEqual(len(bw_usages), 3)
        _compare(bw_usages[0], expected_bw_usages[0])
        _compare(bw_usages[1], expected_bw_usages[1])
        _compare(bw_usages[2], expected_bw_usages[2])
        timeutils.clear_time_override()
コード例 #15
0
ファイル: test_middleware.py プロジェクト: vishvananda/nova
 def tearDown(self):  # pylint: disable=C0103
     timeutils.clear_time_override()
     super(LockoutTestCase, self).tearDown()
コード例 #16
0
ファイル: test_middleware.py プロジェクト: B-Rich/nova-1
 def tearDown(self):  # pylint: disable=C0103
     timeutils.clear_time_override()
     super(LockoutTestCase, self).tearDown()
コード例 #17
0
 def tearDown(self):
     """tearDown method for simple tenant usage."""
     super(SimpleTenantUsageSampleJsonTest, self).tearDown()
     timeutils.clear_time_override()