Python fixtures.MockPatchObject() Examples

The following are 30 code examples of fixtures.MockPatchObject(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fixtures , or try the search function .
Example #1
Source File: test_generator.py    From mistral-extra with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(GeneratorTest, self).setUp()

        # The baremetal inspector client expects the service to be running
        # when it is initialised and attempts to connect. This mocks out this
        # service only and returns a simple function that can be used by the
        # inspection utils.
        self.useFixture(fixtures.MockPatchObject(
            actions.BaremetalIntrospectionAction, "get_fake_client_method",
            return_value=lambda x: None))

        # Do the same for the Zun client.
        # There is no rpm packaging for Zun client
        # so importing the client will fail when building
        # the rpm and running the unittest so lets mock it
        self.useFixture(fixtures.MockPatchObject(
            actions.ZunAction, "get_fake_client_method",
            return_value=lambda x: None))

        # Same for Qinling client
        self.useFixture(fixtures.MockPatchObject(
            actions.QinlingAction, "get_fake_client_method",
            return_value=lambda x: None)) 
Example #2
Source File: test_process.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(BaseProcessTest, self).setUp()

        self.cache_fixture = self.useFixture(
            fixtures.MockPatchObject(node_cache, 'find_node', autospec=True))
        self.process_fixture = self.useFixture(
            fixtures.MockPatchObject(process, '_process_node', autospec=True))

        self.find_mock = self.cache_fixture.mock
        self.node_info = node_cache.NodeInfo(
            uuid=self.node.uuid,
            state=istate.States.waiting,
            started_at=self.started_at)
        self.node_info.finished = mock.Mock()
        self.find_mock.return_value = self.node_info
        self.cli.get_node.return_value = self.node
        self.process_mock = self.process_fixture.mock
        self.process_mock.return_value = self.fake_result_json
        self.addCleanup(self._cleanup_lock, self.node_info) 
Example #3
Source File: test_dnsmasq_pxe_filter.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestMACHandlers, self).setUp()
        self.mac = 'ff:ff:ff:ff:ff:ff'
        self.dhcp_hostsdir = '/far'
        CONF.set_override('dhcp_hostsdir', self.dhcp_hostsdir,
                          'dnsmasq_pxe_filter')
        self.mock_join = self.useFixture(
            fixtures.MockPatchObject(os.path, 'join')).mock
        self.mock_join.return_value = "%s/%s" % (self.dhcp_hostsdir, self.mac)
        self.mock__exclusive_write_or_pass = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_exclusive_write_or_pass')).mock
        self.mock_stat = self.useFixture(
            fixtures.MockPatchObject(os, 'stat')).mock
        self.mock_listdir = self.useFixture(
            fixtures.MockPatchObject(os, 'listdir')).mock
        self.mock_remove = self.useFixture(
            fixtures.MockPatchObject(os, 'remove')).mock
        self.mock_log = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, 'LOG')).mock
        self.mock_introspection_active = self.useFixture(
            fixtures.MockPatchObject(node_cache, 'introspection_active')).mock 
Example #4
Source File: test_dnsmasq_pxe_filter.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestExclusiveWriteOrPass, self).setUp()
        self.mock_open = self.useFixture(fixtures.MockPatchObject(
            builtins, 'open', new=mock.mock_open())).mock
        self.mock_fd = self.mock_open.return_value
        self.mock_fcntl = self.useFixture(fixtures.MockPatchObject(
            dnsmasq.fcntl, 'flock', autospec=True)).mock
        self.path = '/foo/bar/baz'
        self.buf = 'spam'
        self.fcntl_lock_call = mock.call(
            self.mock_fd, dnsmasq.fcntl.LOCK_EX | dnsmasq.fcntl.LOCK_NB)
        self.fcntl_unlock_call = mock.call(self.mock_fd, dnsmasq.fcntl.LOCK_UN)
        self.mock_log = self.useFixture(fixtures.MockPatchObject(
            dnsmasq.LOG, 'debug')).mock
        self.mock_sleep = self.useFixture(fixtures.MockPatchObject(
            dnsmasq.time, 'sleep')).mock 
Example #5
Source File: test_process.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestReapplyNode, self).setUp()
        CONF.set_override('processing_hooks',
                          '$processing.default_processing_hooks,example',
                          'processing')
        CONF.set_override('store_data', 'swift', 'processing')
        self.data['macs'] = self.macs
        self.ports = self.all_ports
        self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                             started_at=self.started_at,
                                             node=self.node)
        self.node_info.invalidate_cache = mock.Mock()

        self.cli.create_port.side_effect = self.ports
        self.cli.update_node.return_value = self.node
        self.cli.ports.return_value = []
        self.node_info._state = istate.States.finished
        self.commit_fixture = self.useFixture(
            fixtures.MockPatchObject(node_cache.NodeInfo, 'commit',
                                     autospec=True))
        db.Node(uuid=self.node_info.uuid, state=self.node_info._state,
                started_at=self.node_info.started_at,
                finished_at=self.node_info.finished_at,
                error=self.node_info.error).save(self.session) 
Example #6
Source File: test_dnsmasq_pxe_filter.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestDnsmasqDriverAPI, self).setUp()
        self.mock__execute = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_execute')).mock
        self.driver._sync = mock.Mock()
        self.driver._tear_down = mock.Mock()
        self.mock__purge_dhcp_hostsdir = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_purge_dhcp_hostsdir')).mock
        self.mock_ironic = mock.Mock()
        get_client_mock = self.useFixture(
            fixtures.MockPatchObject(ir_utils, 'get_client')).mock
        get_client_mock.return_value = self.mock_ironic
        self.start_command = '/far/boo buzz -V --ack 42'
        CONF.set_override('dnsmasq_start_command', self.start_command,
                          'dnsmasq_pxe_filter')
        self.stop_command = '/what/ever'
        CONF.set_override('dnsmasq_stop_command', self.stop_command,
                          'dnsmasq_pxe_filter') 
Example #7
Source File: test_iptables.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestIptablesDriver, self).setUp()
        CONF.set_override('rootwrap_config', '/some/fake/path')
        # NOTE(milan) we ignore the state checking in order to avoid having to
        # always call e.g self.driver.init_filter() to set proper driver state
        self.mock_fsm = self.useFixture(
            fixtures.MockPatchObject(iptables.IptablesFilter, 'fsm')).mock
        self.mock_call = self.useFixture(
            fixtures.MockPatchObject(iptables.processutils, 'execute')).mock
        self.driver = iptables.IptablesFilter()
        self.mock_iptables = self.useFixture(
            fixtures.MockPatchObject(self.driver, '_iptables')).mock
        self.mock_should_enable_dhcp = self.useFixture(
            fixtures.MockPatchObject(iptables, '_should_enable_dhcp')).mock
        self.mock__get_blacklist = self.useFixture(
            fixtures.MockPatchObject(iptables, '_get_blacklist')).mock
        self.mock__get_blacklist.return_value = []
        self.mock_ironic = mock.Mock() 
Example #8
Source File: test_filters.py    From designate with Apache License 2.0 6 votes vote down vote up
def test_policy_failure(self):
        pools = objects.PoolList.from_list(
            [{"id": "6c346011-e581-429b-a7a2-6cdf0aba91c3"}]
        )

        self.useFixture(fixtures.MockPatchObject(
            policy, 'check',
            side_effect=exceptions.Forbidden
        ))

        self.assertRaises(
            exceptions.Forbidden,
            self.test_filter.filter, self.context, pools, self.zone,
        )

        policy.check.assert_called_once_with(
            'zone_create_forced_pool',
            self.context,
            pools[0]) 
Example #9
Source File: test_filters.py    From designate with Apache License 2.0 6 votes vote down vote up
def test_multiple_pools(self):
        pools = objects.PoolList.from_list(
            [
                {"id": "6c346011-e581-429b-a7a2-6cdf0aba91c3"},
                {"id": "5fabcd37-262c-4cf3-8625-7f419434b6df"}
            ]
        )

        self.useFixture(fixtures.MockPatchObject(
            policy, 'check',
            return_value=None
        ))

        pools = self.test_filter.filter(self.context, pools, self.zone)

        self.assertEqual(len(pools), 1)

        self.assertEqual("6c346011-e581-429b-a7a2-6cdf0aba91c3", pools[0].id) 
Example #10
Source File: test_manager.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestManagerInitHost, self).setUp()
        self.mock_db_init = self.useFixture(fixtures.MockPatchObject(
            manager.db, 'init')).mock
        self.mock_validate_processing_hooks = self.useFixture(
            fixtures.MockPatchObject(manager.plugins_base,
                                     'validate_processing_hooks')).mock
        self.mock_filter = self.useFixture(fixtures.MockPatchObject(
            manager.pxe_filter, 'driver')).mock.return_value
        self.mock_PeriodicWorker = self.useFixture(fixtures.MockPatchObject(
            manager.periodics, 'PeriodicWorker')).mock
        self.mock_executor = self.useFixture(fixtures.MockPatchObject(
            manager.utils, 'executor')).mock
        self.mock_ExistingExecutor = self.useFixture(fixtures.MockPatchObject(
            manager.periodics, 'ExistingExecutor')).mock
        self.mock_exit = self.useFixture(fixtures.MockPatchObject(
            manager.sys, 'exit')).mock 
Example #11
Source File: test_tasks.py    From designate with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(PeriodicSecondaryRefreshTest, self).setUp()
        self.useFixture(cfg_fixture.Config(CONF))

        # Mock a ctxt...
        self.ctxt = mock.Mock()
        self.useFixture(fixtures.MockPatchObject(
            context.DesignateContext, 'get_admin_context',
            return_value=self.ctxt
        ))

        # Mock a central...
        self.central = mock.Mock()
        self.useFixture(fixtures.MockPatchObject(
            central_api.CentralAPI, 'get_instance',
            return_value=self.central
        ))

        self.task = tasks.PeriodicSecondaryRefreshTask()
        self.task.my_partitions = 0, 9 
Example #12
Source File: test_introspect.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(BaseTest, self).setUp()
        introspect._LAST_INTROSPECTION_TIME = 0
        self.node.power_state = 'power off'
        self.ports = [mock.Mock(address=m) for m in self.macs]
        self.ports_dict = collections.OrderedDict((p.address, p)
                                                  for p in self.ports)
        self.node_info = mock.Mock(uuid=self.uuid, options={})
        self.node_info.ports.return_value = self.ports_dict
        self.node_info.node.return_value = self.node
        driver_fixture = self.useFixture(fixtures.MockPatchObject(
            pxe_filter, 'driver', autospec=True))
        driver_mock = driver_fixture.mock.return_value
        self.sync_filter_mock = driver_mock.sync

        self.async_exc = None
        executor_fixture = self.useFixture(fixtures.MockPatchObject(
            utils, 'executor', autospec=True))
        self.submit_mock = executor_fixture.mock.return_value.submit
        self.submit_mock.side_effect = self._submit 
Example #13
Source File: test_main.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(BaseAPITest, self).setUp()
        self.init_app()
        self.uuid = uuidutils.generate_uuid()
        self.rpc_get_client_mock = self.useFixture(
            fixtures.MockPatchObject(rpc, 'get_client', autospec=True)).mock
        self.client_mock = mock.MagicMock(spec=messaging.RPCClient)
        self.rpc_get_client_mock.return_value = self.client_mock 
Example #14
Source File: test_wsgi_service.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        # generic mocks setUp method
        super(BaseWSGITest, self).setUp()
        self.app = self.useFixture(fixtures.MockPatchObject(
            main, '_app', autospec=True)).mock
        self.server = self.useFixture(fixtures.MockPatchObject(
            wsgi_service.wsgi, 'Server', autospec=True)).mock 
Example #15
Source File: test_main.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestTopic, self).setUp()
        self.transport_mock = self.useFixture(
            fixtures.MockPatchObject(rpc, 'TRANSPORT',
                                     autospec=True)).mock
        self.target_mock = self.useFixture(
            fixtures.MockPatchObject(rpc.messaging, 'Target',
                                     autospec=True)).mock
        self.rpcclient_mock = self.useFixture(
            fixtures.MockPatchObject(rpc.messaging, 'RPCClient',
                                     autospec=True)).mock
        CONF.set_override('host', 'a-host') 
Example #16
Source File: test_manager.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestManagerDelHost, self).setUp()
        self.mock_filter = self.useFixture(fixtures.MockPatchObject(
            manager.pxe_filter, 'driver')).mock.return_value
        self.mock_executor = mock.Mock()
        self.mock_executor.alive = True
        self.mock_get_executor = self.useFixture(fixtures.MockPatchObject(
            manager.utils, 'executor')).mock
        self.mock_get_executor.return_value = self.mock_executor
        self.mock__periodic_worker = self.useFixture(fixtures.MockPatchObject(
            self.manager, '_periodics_worker')).mock
        self.mock_exit = self.useFixture(fixtures.MockPatchObject(
            manager.sys, 'exit')).mock 
Example #17
Source File: test_dnsmasq_pxe_filter.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def test_tear_down_filter(self):
        mock_reset = self.useFixture(
            fixtures.MockPatchObject(self.driver, 'reset')).mock
        self.driver.init_filter()
        self.driver.tear_down_filter()

        mock_reset.assert_called_once_with() 
Example #18
Source File: test_manager.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(BaseManagerTest, self).setUp()
        self.mock_log = self.useFixture(fixtures.MockPatchObject(
            manager, 'LOG')).mock
        self.mock__shutting_down = (self.useFixture(fixtures.MockPatchObject(
            manager.semaphore, 'Semaphore', autospec=True))
            .mock.return_value)
        self.mock__shutting_down.acquire.return_value = True
        self.manager = manager.ConductorManager()
        self.context = {} 
Example #19
Source File: test_dnsmasq_pxe_filter.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestSync, self).setUp()
        self.mock__get_black_white_lists = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_get_black_white_lists')).mock
        self.mock__whitelist_mac = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_whitelist_mac')).mock
        self.mock__blacklist_mac = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_blacklist_mac')).mock
        self.mock__configure_unknown_hosts = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_configure_unknown_hosts')).mock
        self.mock__configure_removedlist = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_configure_removedlist')).mock

        self.mock_ironic = mock.Mock()
        self.mock_utcnow = self.useFixture(
            fixtures.MockPatchObject(dnsmasq.timeutils, 'utcnow')).mock
        self.timestamp_start = datetime.datetime.utcnow()
        self.timestamp_end = (self.timestamp_start +
                              datetime.timedelta(seconds=42))
        self.mock_utcnow.side_effect = [self.timestamp_start,
                                        self.timestamp_end]
        self.mock_log = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, 'LOG')).mock
        get_client_mock = self.useFixture(
            fixtures.MockPatchObject(ir_utils, 'get_client')).mock
        get_client_mock.return_value = self.mock_ironic
        self.mock_active_macs = self.useFixture(
            fixtures.MockPatchObject(node_cache, 'active_macs')).mock
        self.ironic_macs = {'new_mac', 'active_mac'}
        self.active_macs = {'active_mac'}
        self.blacklist = {'gone_mac', 'active_mac'}
        self.whitelist = {}
        self.mock__get_black_white_lists.return_value = (self.blacklist,
                                                         self.whitelist)
        self.mock_ironic.ports.return_value = [
            mock.Mock(address=address) for address in self.ironic_macs]
        self.mock_active_macs.return_value = self.active_macs
        self.mock_should_enable_unknown_hosts = self.useFixture(
            fixtures.MockPatchObject(dnsmasq,
                                     '_should_enable_unknown_hosts')).mock
        self.mock_should_enable_unknown_hosts.return_value = True 
Example #20
Source File: test_pxe_filter.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def test_get_periodic_sync_task_custom_error(self):
        class MyError(Exception):
            pass

        sync_mock = self.useFixture(
            fixtures.MockPatchObject(self.driver, 'sync')).mock
        sync_mock.side_effect = MyError('Oops!')

        self.driver.get_periodic_sync_task()
        self.mock_periodic.assert_called_once_with(spacing=15, enabled=True)
        self.assertRaisesRegex(
            MyError, 'Oops!', self.mock_periodic.return_value.call_args[0][0]) 
Example #21
Source File: test_wsgi_service.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestWSGIServiceInitMiddleware, self).setUp()
        self.mock_add_auth_middleware = self.useFixture(
            fixtures.MockPatchObject(utils, 'add_auth_middleware')).mock
        self.mock_add_basic_auth_middleware = self.useFixture(
            fixtures.MockPatchObject(utils, 'add_basic_auth_middleware')).mock
        self.mock_add_cors_middleware = self.useFixture(
            fixtures.MockPatchObject(utils, 'add_cors_middleware')).mock
        self.mock_log = self.useFixture(fixtures.MockPatchObject(
            main, 'LOG')).mock
        # 'positive' settings
        CONF.set_override('auth_strategy', 'keystone')
        CONF.set_override('store_data', 'swift', 'processing') 
Example #22
Source File: test_wsgi_service.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestWSGIService, self).setUp()
        self.service = wsgi_service.WSGIService()
        self.service.server = self.server
        self.mock__init_middleware = self.useFixture(fixtures.MockPatchObject(
            main, '_init_middleware')).mock

        # 'positive' settings
        CONF.set_override('listen_address', '42.42.42.42')
        CONF.set_override('listen_port', 42) 
Example #23
Source File: test_iptables.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def _test__iptables_args(self, expected_port):
        self.driver = iptables.IptablesFilter()
        self.mock_iptables = self.useFixture(
            fixtures.MockPatchObject(self.driver, '_iptables')).mock
        self.mock_should_enable_dhcp.return_value = True

        _iptables_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             expected_port, '-j', self.driver.new_chain),
            ('-F', self.driver.new_chain),
            ('-X', self.driver.new_chain),
            ('-N', self.driver.new_chain),
            ('-A', self.driver.new_chain, '-j', 'ACCEPT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             expected_port, '-j', self.driver.new_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             expected_port, '-j', self.driver.chain),
            ('-F', self.driver.chain),
            ('-X', self.driver.chain),
            ('-E', self.driver.new_chain, self.driver.chain)
        ]

        self.driver.sync(self.mock_ironic)
        call_args_list = self.mock_iptables.call_args_list

        for (args, call) in zip(_iptables_expected_args,
                                call_args_list):
            self.assertEqual(args, call[0])
        self.mock__get_blacklist.assert_called_once_with(self.mock_ironic)
        self.check_fsm([pxe_filter.Events.sync]) 
Example #24
Source File: test_iptables.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(Test_ShouldEnableDhcp, self).setUp()
        self.mock_introspection_active = self.useFixture(
            fixtures.MockPatchObject(node_cache, 'introspection_active')).mock 
Example #25
Source File: test_iptables.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestGetBlacklist, self).setUp()
        self.mock__ib_mac_to_rmac_mapping = self.useFixture(
            fixtures.MockPatchObject(iptables, '_ib_mac_to_rmac_mapping')).mock
        self.mock_active_macs = self.useFixture(
            fixtures.MockPatchObject(node_cache, 'active_macs')).mock
        self.mock_ironic = mock.Mock() 
Example #26
Source File: functional.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(Base, self).setUp()
        rules.delete_all()

        self.cli_fixture = self.useFixture(
            fixtures.MockPatchObject(ir_utils, 'get_client'))
        self.cli = self.cli_fixture.mock.return_value
        self.cli.get_node.return_value = self.node
        self.cli.patch_node.return_value = self.node
        self.cli.nodes.return_value = [self.node]

        self.patch = [
            {'op': 'add', 'path': '/properties/cpus', 'value': '4'},
            {'path': '/properties/cpu_arch', 'value': 'x86_64', 'op': 'add'},
            {'op': 'add', 'path': '/properties/memory_mb', 'value': '12288'},
            {'path': '/properties/local_gb', 'value': '999', 'op': 'add'}
        ]
        self.patch_root_hints = [
            {'op': 'add', 'path': '/properties/cpus', 'value': '4'},
            {'path': '/properties/cpu_arch', 'value': 'x86_64', 'op': 'add'},
            {'op': 'add', 'path': '/properties/memory_mb', 'value': '12288'},
            {'path': '/properties/local_gb', 'value': '19', 'op': 'add'}
        ]

        self.node.power_state = 'power off'

        self.cfg = self.useFixture(config_fixture.Config())
        conf_file = get_test_conf_file()
        self.cfg.set_config_files([conf_file])

        # FIXME(milan) FakeListener.poll calls time.sleep() which leads to
        # busy polling with no sleep at all, effectively blocking the whole
        # process by consuming all CPU cycles in a single thread. MonkeyPatch
        # with eventlet.sleep seems to help this.
        self.useFixture(fixtures.MonkeyPatch(
            'oslo_messaging._drivers.impl_fake.time.sleep', eventlet.sleep)) 
Example #27
Source File: test_query.py    From aodh with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestQueryToKwArgs, self).setUp()
        self.useFixture(fixtures.MockPatchObject(
            utils, 'sanitize_query', side_effect=lambda x, y, **z: x))
        self.useFixture(fixtures.MockPatchObject(
            utils, '_verify_query_segregation', side_effect=lambda x, **z: x)) 
Example #28
Source File: test_mockpatch.py    From oslotest with Apache License 2.0 5 votes vote down vote up
def test_reference(self):
        # Applications expect these public symbols to be available until the
        # deprecated module is removed.
        self.assertTrue(fixtures.MockPatchObject)
        self.assertTrue(fixtures.MockPatch)
        self.assertTrue(fixtures.MockPatchMultiple) 
Example #29
Source File: base.py    From ironic-inspector with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(NodeTest, self).setUp()
        self.uuid = uuidutils.generate_uuid()

        fake_node = {
            'driver': 'ipmi',
            'driver_info': {'ipmi_address': self.bmc_address},
            'properties': {'cpu_arch': 'i386', 'local_gb': 40},
            'id': self.uuid,
            'power_state': 'power on',
            'provision_state': 'inspecting',
            'extra': {},
            'instance_uuid': None,
            'maintenance': False
        }
        # TODO(rpittau) the correct value is id, not uuid, based on the
        # openstacksdk schema. The code and the fake_node date are correct
        # but all the tests still use uuid, so just making it equal to id
        # until we find the courage to change it in all tests.
        fake_node['uuid'] = fake_node['id']
        mock_to_dict = mock.Mock(return_value=fake_node)

        self.node = mock.Mock(**fake_node)
        self.node.to_dict = mock_to_dict

        self.ports = []
        self.node_info = node_cache.NodeInfo(
            uuid=self.uuid,
            started_at=datetime.datetime(1, 1, 1),
            node=self.node, ports=self.ports)
        self.node_info.node = mock.Mock(return_value=self.node)
        self.sleep_fixture = self.useFixture(
            fixtures.MockPatchObject(time, 'sleep', autospec=True)) 
Example #30
Source File: test_tasks.py    From designate with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(PeriodicExistsTest, self).setUp()
        self.useFixture(cfg_fixture.Config(CONF))

        CONF.set_override('interval', 5, 'producer_task:periodic_exists')

        # Mock a ctxt...
        self.ctxt = mock.Mock()
        self.useFixture(fixtures.MockPatchObject(
            context.DesignateContext, 'get_admin_context',
            return_value=self.ctxt
        ))

        # Patch get_notifier so that it returns a mock..
        self.mock_notifier = mock.Mock()
        self.useFixture(fixtures.MockPatchObject(
            rpc, 'get_notifier',
            return_value=self.mock_notifier
        ))

        self.task = tasks.PeriodicExistsTask()
        self.task.my_partitions = range(0, 10)

        # Install our own period results to verify that the end / start is
        # correct below
        self.period = tasks.PeriodicExistsTask._get_period(2)
        self.period_data = {
            "audit_period_beginning": self.period[0],
            "audit_period_ending": self.period[1]
        }
        self.useFixture(fixtures.MockPatchObject(
            tasks.PeriodicExistsTask, '_get_period',
            return_value=self.period
        ))