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()
Esempio n. 2
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()
Esempio n. 3
0
    def test_utcnow(self):
        timeutils.set_time_override(mock.sentinel.utcnow)
        self.assertEqual(timeutils.utcnow(), mock.sentinel.utcnow)

        timeutils.clear_time_override()
        self.assertFalse(timeutils.utcnow() == mock.sentinel.utcnow)

        self.assertTrue(timeutils.utcnow())
Esempio n. 4
0
    def test_utcnow(self):
        timeutils.set_time_override(mock.sentinel.utcnow)
        self.assertEqual(timeutils.utcnow(), mock.sentinel.utcnow)

        timeutils.clear_time_override()
        self.assertFalse(timeutils.utcnow() == mock.sentinel.utcnow)

        self.assertTrue(timeutils.utcnow())
Esempio n. 5
0
 def tearDown(self):
     super(ServicesJsonTest, self).tearDown()
     timeutils.clear_time_override()
Esempio n. 6
0
 def tearDown(self):
     timeutils.clear_time_override()
     super(AuditPeriodTest, self).tearDown()
Esempio n. 7
0
 def tearDown(self):  # pylint: disable=C0103
     timeutils.clear_time_override()
     super(LockoutTestCase, self).tearDown()
Esempio n. 8
0
 def tearDown(self):  # pylint: disable=C0103
     timeutils.clear_time_override()
     super(LockoutTestCase, self).tearDown()
Esempio n. 9
0
 def tearDown(self):
     timeutils.clear_time_override()
     super(LockoutTestCase, self).tearDown()
Esempio n. 10
0
 def tearDown(self):
     timeutils.clear_time_override()
     super(AuditPeriodTest, self).tearDown()
Esempio n. 11
0
 def tearDown(self):
     """tearDown method for simple tenant usage."""
     super(SimpleTenantUsageSampleJsonTest, self).tearDown()
     timeutils.clear_time_override()
 def tearDown(self):
     super(MuteWeigherTestClass, self).tearDown()
     timeutils.clear_time_override()
 def tearDown(self):
     timeutils.clear_time_override()
     super(LockoutTestCase, self).tearDown()
Esempio n. 14
0
 def tearDown(self):
     """tearDown method for simple tenant usage."""
     super(SimpleTenantUsageSampleJsonTest, self).tearDown()
     timeutils.clear_time_override()
Esempio n. 15
0
 def tearDown(self):
     super(InstanceUsageAuditLogTestV21, self).tearDown()
     timeutils.clear_time_override()
 def tearDown(self):
     super(InstanceUsageAuditLogTestV21, self).tearDown()
     timeutils.clear_time_override()
Esempio n. 17
0
 def tearDown(self):
     super(MuteWeigherTestClass, self).tearDown()
     timeutils.clear_time_override()