示例#1
0
    def test_memcached_driver(self):
        serv = self.useFixture(
            ServiceFixture(self._host, self._binary, self._topic)).serv
        serv.start()
        service_ref = db.service_get_by_args(self._ctx,
                                             self._host,
                                             self._binary)
        hostkey = str("%s:%s" % (self._topic, self._host))
        self.servicegroup_api._driver.mc.set(hostkey,
                                             timeutils.utcnow(),
                                             time=self.down_time)

        self.assertTrue(self.servicegroup_api.service_is_up(service_ref))
        self.useFixture(test.TimeOverride())
        timeutils.advance_time_seconds(self.down_time + 1)
        self.servicegroup_api._driver._report_state(serv)
        service_ref = db.service_get_by_args(self._ctx,
                                             self._host,
                                             self._binary)

        self.assertTrue(self.servicegroup_api.service_is_up(service_ref))
        serv.stop()
        timeutils.advance_time_seconds(self.down_time + 1)
        service_ref = db.service_get_by_args(self._ctx,
                                             self._host,
                                             self._binary)
        self.assertFalse(self.servicegroup_api.service_is_up(service_ref))
示例#2
0
    def test_shelved_poll_timedout(self):
        active_instance = jsonutils.to_primitive(self._create_fake_instance())
        self.compute.run_instance(self.context, active_instance, {}, {}, [],
                                  None, None, True, None, False)

        instance = jsonutils.to_primitive(self._create_fake_instance())
        self.compute.run_instance(self.context, instance, {}, {}, [], None,
                                  None, True, None, False)
        sys_meta = utils.metadata_to_dict(instance['system_metadata'])
        shelved_time = timeutils.utcnow()
        timeutils.set_time_override(shelved_time)
        timeutils.advance_time_seconds(CONF.shelved_offload_time + 1)
        sys_meta['shelved_at'] = timeutils.strtime(at=shelved_time)
        (old, instance) = db.instance_update_and_get_original(
            self.context, instance['uuid'], {
                'vm_state': vm_states.SHELVED,
                'system_metadata': sys_meta
            })

        def fake_destroy(inst, nw_info, bdm):
            # NOTE(alaski) There are too many differences between an instance
            # as returned by instance_update_and_get_original and
            # instance_get_all_by_filters so just compare the uuid.
            self.assertEqual(instance['uuid'], inst['uuid'])

        self.stubs.Set(self.compute.driver, 'destroy', fake_destroy)
        self.compute._poll_shelved_instances(self.context)
示例#3
0
 def test_log_progress_if_not_required(self):
     self.mox.StubOutWithMock(vm_utils.LOG, "debug")
     current = timeutils.utcnow()
     timeutils.set_time_override(current)
     timeutils.advance_time_seconds(vm_utils.PROGRESS_INTERVAL_SECONDS - 1)
     self.mox.ReplayAll()
     vm_utils._log_progress_if_required(1, current, 2)
示例#4
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()
示例#5
0
 def test_log_progress_if_not_required(self):
     self.mox.StubOutWithMock(vm_utils.LOG, "debug")
     current = timeutils.utcnow()
     timeutils.set_time_override(current)
     timeutils.advance_time_seconds(vm_utils.PROGRESS_INTERVAL_SECONDS - 1)
     self.mox.ReplayAll()
     vm_utils._log_progress_if_required(1, current, 2)
示例#6
0
 def test_multiple_keys(self):
     self._send_bad_attempts('test1', FLAGS.lockout_attempts)
     self.assertTrue(self._is_locked_out('test1'))
     self.assertFalse(self._is_locked_out('test2'))
     timeutils.advance_time_seconds(FLAGS.lockout_minutes * 60)
     self.assertFalse(self._is_locked_out('test1'))
     self.assertFalse(self._is_locked_out('test2'))
示例#7
0
 def test_multiple_keys(self):
     self._send_bad_attempts('test1', CONF.lockout_attempts)
     self.assertTrue(self._is_locked_out('test1'))
     self.assertFalse(self._is_locked_out('test2'))
     timeutils.advance_time_seconds(CONF.lockout_minutes * 60)
     self.assertFalse(self._is_locked_out('test1'))
     self.assertFalse(self._is_locked_out('test2'))
示例#8
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()
示例#9
0
    def test_shelved_poll_timedout(self):
        active_instance = jsonutils.to_primitive(self._create_fake_instance())
        self.compute.run_instance(self.context, active_instance, {}, {}, [],
                None, None, True, None, False)

        instance = jsonutils.to_primitive(self._create_fake_instance())
        self.compute.run_instance(self.context, instance, {}, {}, [], None,
                None, True, None, False)
        sys_meta = utils.metadata_to_dict(instance['system_metadata'])
        shelved_time = timeutils.utcnow()
        timeutils.set_time_override(shelved_time)
        timeutils.advance_time_seconds(CONF.shelved_offload_time + 1)
        sys_meta['shelved_at'] = timeutils.strtime(at=shelved_time)
        (old, instance) = db.instance_update_and_get_original(self.context,
                instance['uuid'], {'vm_state': vm_states.SHELVED,
                                   'system_metadata': sys_meta})

        def fake_destroy(inst, nw_info, bdm):
            # NOTE(alaski) There are too many differences between an instance
            # as returned by instance_update_and_get_original and
            # instance_get_all_by_filters so just compare the uuid.
            self.assertEqual(instance['uuid'], inst['uuid'])

        self.stubs.Set(self.compute.driver, 'destroy', fake_destroy)
        self.compute._poll_shelved_instances(self.context)
示例#10
0
 def test_tokens_expire(self):
     """Test that tokens expire correctly."""
     self.useFixture(test.TimeOverride())
     token = "mytok"
     self.flags(console_token_ttl=1)
     self.manager.authorize_console(self.context, token, "novnc", "127.0.0.1", "host", "")
     self.assertTrue(self.manager.check_token(self.context, token))
     timeutils.advance_time_seconds(1)
     self.assertFalse(self.manager.check_token(self.context, token))
示例#11
0
 def test_tokens_expire(self):
     # Test that tokens expire correctly.
     self.useFixture(test.TimeOverride())
     token = 'mytok'
     self.flags(console_token_ttl=1)
     self.manager.authorize_console(self.context, token, 'novnc',
                                    '127.0.0.1', 'host', '')
     self.assertTrue(self.manager.check_token(self.context, token))
     timeutils.advance_time_seconds(1)
     self.assertFalse(self.manager.check_token(self.context, token))
示例#12
0
 def test_tokens_expire(self):
     # Test that tokens expire correctly.
     self.useFixture(test.TimeOverride())
     token = 'mytok'
     self.flags(console_token_ttl=1)
     self.manager.authorize_console(self.context, token, 'novnc',
                                    '127.0.0.1', 'host', '')
     self.assertTrue(self.manager.check_token(self.context, token))
     timeutils.advance_time_seconds(1)
     self.assertFalse(self.manager.check_token(self.context, token))
示例#13
0
 def test_log_progress_if_required(self):
     self.mox.StubOutWithMock(vm_utils.LOG, "debug")
     vm_utils.LOG.debug(_("Sparse copy in progress, "
                          "%(complete_pct).2f%% complete. "
                          "%(left) bytes left to copy"),
                        {"complete_pct": 50.0, "left": 1})
     current = timeutils.utcnow()
     timeutils.set_time_override(current)
     timeutils.advance_time_seconds(vm_utils.PROGRESS_INTERVAL_SECONDS + 1)
     self.mox.ReplayAll()
     vm_utils._log_progress_if_required(1, current, 2)
示例#14
0
 def test_log_progress_if_required(self):
     self.mox.StubOutWithMock(vm_utils.LOG, "debug")
     vm_utils.LOG.debug(_("Sparse copy in progress, "
                          "%(complete_pct).2f%% complete. "
                          "%(left) bytes left to copy"),
                        {"complete_pct": 50.0, "left": 1})
     current = timeutils.utcnow()
     timeutils.set_time_override(current)
     timeutils.advance_time_seconds(vm_utils.PROGRESS_INTERVAL_SECONDS + 1)
     self.mox.ReplayAll()
     vm_utils._log_progress_if_required(1, current, 2)
示例#15
0
    def test_tokens_expire(self):
        # Test that tokens expire correctly.
        self.useFixture(test.TimeOverride())
        token = u"mytok"
        self.flags(console_token_ttl=1)

        self._stub_validate_console_port(True)

        self.manager.authorize_console(self.context, token, "novnc", "127.0.0.1", "8080", "host", "instance")
        self.assertTrue(self.manager.check_token(self.context, token))
        timeutils.advance_time_seconds(1)
        self.assertFalse(self.manager.check_token(self.context, token))
示例#16
0
    def test_shelved_poll_not_timedout(self):
        instance = jsonutils.to_primitive(self._create_fake_instance())
        sys_meta = utils.metadata_to_dict(instance['system_metadata'])
        shelved_time = timeutils.utcnow()
        timeutils.set_time_override(shelved_time)
        timeutils.advance_time_seconds(CONF.shelved_offload_time - 1)
        sys_meta['shelved_at'] = timeutils.strtime(at=shelved_time)
        db.instance_update_and_get_original(self.context, instance['uuid'],
                {'vm_state': vm_states.SHELVED, 'system_metadata': sys_meta})

        self.mox.StubOutWithMock(self.compute.driver, 'destroy')
        self.mox.ReplayAll()
        self.compute._poll_shelved_instances(self.context)
示例#17
0
    def test_tokens_expire(self):
        # Test that tokens expire correctly.
        self.useFixture(test.TimeOverride())
        token = u'mytok'
        self.flags(console_token_ttl=1)

        self._stub_validate_console_port(True)

        self.manager_api.authorize_console(self.context, token, 'novnc',
                                         '127.0.0.1', '8080', 'host',
                                         self.instance['uuid'])
        self.assertTrue(self.manager_api.check_token(self.context, token))
        timeutils.advance_time_seconds(1)
        self.assertFalse(self.manager_api.check_token(self.context, token))
示例#18
0
    def test_tokens_expire(self):
        # Test that tokens expire correctly.
        self.useFixture(test.TimeOverride())
        token = u'mytok'
        self.flags(console_token_ttl=1)

        self._stub_validate_console_port(True)

        self.manager_api.authorize_console(self.context, token, 'novnc',
                                           '127.0.0.1', '8080', 'host',
                                           self.instance['uuid'])
        self.assertTrue(self.manager_api.check_token(self.context, token))
        timeutils.advance_time_seconds(1)
        self.assertFalse(self.manager_api.check_token(self.context, token))
    def test_shelved_poll_not_timedout(self):
        instance = jsonutils.to_primitive(self._create_fake_instance())
        self.compute.run_instance(self.context, instance=instance)
        sys_meta = utils.metadata_to_dict(instance['system_metadata'])
        shelved_time = timeutils.utcnow()
        timeutils.set_time_override(shelved_time)
        timeutils.advance_time_seconds(CONF.shelved_offload_time - 1)
        sys_meta['shelved_at'] = timeutils.strtime(at=shelved_time)
        db.instance_update_and_get_original(self.context, instance['uuid'],
                {'vm_state': vm_states.SHELVED, 'system_metadata': sys_meta})

        self.mox.StubOutWithMock(self.compute.driver, 'destroy')
        self.mox.ReplayAll()
        self.compute._poll_shelved_instances(self.context)
示例#20
0
    def test_shelved_poll_not_timedout(self):
        instance = jsonutils.to_primitive(self._create_fake_instance())
        self.compute.run_instance(self.context, instance, {}, {}, [], None, None, True, None, False)
        sys_meta = utils.metadata_to_dict(instance["system_metadata"])
        shelved_time = timeutils.utcnow()
        timeutils.set_time_override(shelved_time)
        timeutils.advance_time_seconds(CONF.shelved_offload_time - 1)
        sys_meta["shelved_at"] = timeutils.strtime(at=shelved_time)
        db.instance_update_and_get_original(
            self.context, instance["uuid"], {"vm_state": vm_states.SHELVED, "system_metadata": sys_meta}
        )

        self.mox.StubOutWithMock(self.compute.driver, "destroy")
        self.mox.ReplayAll()
        self.compute._poll_shelved_instances(self.context)
示例#21
0
    def test_DB_driver(self):
        serv = self.useFixture(ServiceFixture(self._host, self._binary, self._topic)).serv
        serv.start()
        service_ref = db.service_get_by_args(self._ctx, self._host, self._binary)

        self.assertTrue(self.servicegroup_api.service_is_up(service_ref))
        self.useFixture(test.TimeOverride())
        timeutils.advance_time_seconds(self.down_time + 1)
        self.servicegroup_api._driver._report_state(serv)
        service_ref = db.service_get_by_args(self._ctx, self._host, self._binary)

        self.assertTrue(self.servicegroup_api.service_is_up(service_ref))
        serv.stop()
        timeutils.advance_time_seconds(self.down_time + 1)
        service_ref = db.service_get_by_args(self._ctx, self._host, self._binary)
        self.assertFalse(self.servicegroup_api.service_is_up(service_ref))
示例#22
0
    def test_tokens_expire(self):
        # Test that tokens expire correctly.
        self.useFixture(test.TimeOverride())
        token = 'mytok'
        self.flags(console_token_ttl=1)

        def fake_validate_console_port(*args, **kwargs):
            return True
        self.stubs.Set(self.manager.compute_rpcapi,
                       "validate_console_port",
                       fake_validate_console_port)

        self.manager.authorize_console(self.context, token, 'novnc',
                                         '127.0.0.1', '8080', 'host',
                                         'instance')
        self.assertTrue(self.manager.check_token(self.context, token))
        timeutils.advance_time_seconds(1)
        self.assertFalse(self.manager.check_token(self.context, token))
示例#23
0
    def test_shelved_poll_timedout(self):
        instance = jsonutils.to_primitive(self._create_fake_instance())
        sys_meta = utils.metadata_to_dict(instance["system_metadata"])
        shelved_time = timeutils.utcnow()
        timeutils.set_time_override(shelved_time)
        timeutils.advance_time_seconds(CONF.shelved_offload_time + 1)
        sys_meta["shelved_at"] = timeutils.strtime(at=shelved_time)
        (old, instance) = db.instance_update_and_get_original(
            self.context, instance["uuid"], {"vm_state": vm_states.SHELVED, "system_metadata": sys_meta}
        )

        def fake_destroy(inst, nw_info, bdm):
            # NOTE(alaski) There are too many differences between an instance
            # as returned by instance_update_and_get_original and
            # instance_get_all_by_filters so just compare the uuid.
            self.assertEqual(instance["uuid"], inst["uuid"])

        self.stubs.Set(self.compute.driver, "destroy", fake_destroy)
        self.compute._poll_shelved_instances(self.context)
示例#24
0
    def test_DB_driver(self):
        serv = self.useFixture(
            ServiceFixture(self._host, self._binary, self._topic)).serv
        serv.start()
        service_ref = db.service_get_by_args(self._ctx, self._host,
                                             self._binary)

        self.assertTrue(self.servicegroup_api.service_is_up(service_ref))
        self.useFixture(test.TimeOverride())
        timeutils.advance_time_seconds(self.down_time + 1)
        self.servicegroup_api._driver._report_state(serv)
        service_ref = db.service_get_by_args(self._ctx, self._host,
                                             self._binary)

        self.assertTrue(self.servicegroup_api.service_is_up(service_ref))
        serv.stop()
        timeutils.advance_time_seconds(self.down_time + 1)
        service_ref = db.service_get_by_args(self._ctx, self._host,
                                             self._binary)
        self.assertFalse(self.servicegroup_api.service_is_up(service_ref))
示例#25
0
    def test_delete_expired_tokens(self):
        self.useFixture(test.TimeOverride())
        token = u'mytok'
        self.flags(console_token_ttl=1)

        self._stub_validate_console_port(True)

        self.manager_api.authorize_console(self.context, token, 'novnc',
                                           '127.0.0.1', '8080', 'host',
                                           self.instance['uuid'])
        timeutils.advance_time_seconds(1)
        self.assertFalse(self.manager_api.check_token(self.context, token))

        token1 = u'mytok2'
        self.manager_api.authorize_console(self.context, token1, 'novnc',
                                           '127.0.0.1', '8080', 'host',
                                           self.instance['uuid'])
        stored_tokens = self.manager._get_tokens_for_instance(
            self.instance['uuid'])
        # when trying to store token1, expired token is removed fist.
        self.assertEqual(len(stored_tokens), 1)
        self.assertEqual(stored_tokens[0], token1)
示例#26
0
    def test_delete_expired_tokens(self):
        self.useFixture(test.TimeOverride())
        token = u'mytok'
        self.flags(console_token_ttl=1)

        self._stub_validate_console_port(True)

        self.manager_api.authorize_console(self.context, token, 'novnc',
                                         '127.0.0.1', '8080', 'host',
                                         self.instance['uuid'])
        timeutils.advance_time_seconds(1)
        self.assertFalse(self.manager_api.check_token(self.context, token))

        token1 = u'mytok2'
        self.manager_api.authorize_console(self.context, token1, 'novnc',
                                       '127.0.0.1', '8080', 'host',
                                       self.instance['uuid'])
        stored_tokens = self.manager._get_tokens_for_instance(
                self.instance['uuid'])
        # when trying to store token1, expired token is removed fist.
        self.assertEqual(len(stored_tokens), 1)
        self.assertEqual(stored_tokens[0], token1)
示例#27
0
 def test_window_timeout(self):
     self._send_bad_attempts('test', CONF.lockout_attempts - 1)
     self.assertFalse(self._is_locked_out('test'))
     timeutils.advance_time_seconds(CONF.lockout_window * 60)
     self._send_bad_attempts('test', CONF.lockout_attempts - 1)
     self.assertFalse(self._is_locked_out('test'))
示例#28
0
 def test_timeout(self):
     self._send_bad_attempts('test', CONF.lockout_attempts)
     self.assertTrue(self._is_locked_out('test'))
     timeutils.advance_time_seconds(CONF.lockout_minutes * 60)
     self.assertFalse(self._is_locked_out('test'))
示例#29
0
 def test_timeout(self):
     self._send_bad_attempts('test', FLAGS.lockout_attempts)
     self.assertTrue(self._is_locked_out('test'))
     timeutils.advance_time_seconds(FLAGS.lockout_minutes * 60)
     self.assertFalse(self._is_locked_out('test'))
示例#30
0
 def test_window_timeout(self):
     self._send_bad_attempts('test', FLAGS.lockout_attempts - 1)
     self.assertFalse(self._is_locked_out('test'))
     timeutils.advance_time_seconds(FLAGS.lockout_window * 60)
     self._send_bad_attempts('test', FLAGS.lockout_attempts - 1)
     self.assertFalse(self._is_locked_out('test'))
 def test_timeout(self):
     self._send_bad_attempts("test", CONF.lockout_attempts)
     self.assertTrue(self._is_locked_out("test"))
     timeutils.advance_time_seconds(CONF.lockout_minutes * 60)
     self.assertFalse(self._is_locked_out("test"))