def test_acquire_non_blocking(self, get_lock_mock):
        node_info = node_cache.NodeInfo(self.uuid)
        self.assertFalse(node_info._locked)
        get_lock_mock.return_value.acquire.side_effect = iter([False, True])

        self.assertFalse(node_info.acquire_lock(blocking=False))
        self.assertFalse(node_info._locked)
        self.assertTrue(node_info.acquire_lock(blocking=False))
        self.assertTrue(node_info._locked)
        self.assertTrue(node_info.acquire_lock(blocking=False))
        self.assertTrue(node_info._locked)
        get_lock_mock.return_value.acquire.assert_called_with(False)
        self.assertEqual(2, get_lock_mock.return_value.acquire.call_count)
 def setUp(self):
     super(TestValidateInterfacesHookBeforeUpdateDeletion, self).setUp()
     self.hook = std_plugins.ValidateInterfacesHook()
     self.interfaces_to_create = sorted(self.valid_interfaces.values(),
                                        key=lambda i: i['mac'])
     self.existing_ports = [
         mock.Mock(spec=['address', 'uuid'], address=a)
         for a in (self.macs[1], '44:44:44:44:44:44')
     ]
     self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                          started_at=0,
                                          node=self.node,
                                          ports=self.existing_ports)
Ejemplo n.º 3
0
 def setUp(self):
     super(TestSchedulerHook, self).setUp()
     self.hook = std_plugins.SchedulerHook()
     self.data = {
         'local_gb': 20,
         'memory_mb': 1024,
         'cpus': 2,
         'cpu_arch': 'x86_64'
     }
     self.node_patches = []
     self.ports_patches = {}
     self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                          started_at=0,
                                          node=self.node)
Ejemplo n.º 4
0
    def setUp(self):
        super(TestProcessNode, self).setUp()
        CONF.set_override('processing_hooks',
                          '$processing.default_processing_hooks,example',
                          'processing')
        self.validate_attempts = 5
        self.data['macs'] = self.macs  # validate_interfaces hook
        self.data['all_interfaces'] = self.data['interfaces']
        self.ports = self.all_ports
        self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                             started_at=self.started_at,
                                             node=self.node)
        self.patch_props = [{
            'path': '/properties/cpus',
            'value': '2',
            'op': 'add'
        }, {
            'path': '/properties/cpu_arch',
            'value': 'x86_64',
            'op': 'add'
        }, {
            'path': '/properties/memory_mb',
            'value': '1024',
            'op': 'add'
        }, {
            'path': '/properties/local_gb',
            'value': '20',
            'op': 'add'
        }]  # scheduler hook
        self.new_creds = ('user', 'password')
        self.patch_credentials = [
            {
                'op': 'add',
                'path': '/driver_info/ipmi_username',
                'value': self.new_creds[0]
            },
            {
                'op': 'add',
                'path': '/driver_info/ipmi_password',
                'value': self.new_creds[1]
            },
        ]

        self.cli = mock.Mock()
        self.cli.node.get_boot_device.side_effect = (
            [RuntimeError()] * self.validate_attempts + [None])
        self.cli.port.create.side_effect = self.ports
        self.cli.node.update.return_value = self.node
        self.cli.node.list_ports.return_value = []
Ejemplo n.º 5
0
    def test_add_attribute_same_value(self):
        session = db.get_session()
        with session.begin():
            db.Node(uuid=self.node.uuid,
                    state=istate.States.starting).save(session)
        node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=42)

        node_info.add_attribute('key', 'value')
        node_info.add_attribute('key', 'value')
        res = db.model_query(db.Attribute.name,
                             db.Attribute.value,
                             db.Attribute.node_uuid,
                             session=session)
        self.assertEqual([('key', 'value', self.uuid),
                          ('key', 'value', self.uuid)],
                         [tuple(row) for row in res])
Ejemplo n.º 6
0
    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,
                                             started_at=self.started_at)
        self.node_info.finished = mock.Mock()
        self.find_mock.return_value = self.node_info
        self.cli.node.get.return_value = self.node
        self.process_mock = self.process_fixture.mock
        self.process_mock.return_value = self.fake_result_json
Ejemplo n.º 7
0
 def test_no_overwrite(self, mock_patch):
     ports = [
         mock.Mock(spec=['address', 'uuid', 'physical_network'],
                   address=a,
                   physical_network='foo') for a in ('11:11:11:11:11:11', )
     ]
     node_info = node_cache.NodeInfo(uuid=self.uuid,
                                     started_at=0,
                                     node=self.node,
                                     ports=ports)
     cfg.CONF.set_override('overwrite_existing', False, group='processing')
     cfg.CONF.set_override('cidr_map',
                           '1.1.1.0/24:physnet_a',
                           group='port_physnet')
     self.hook.before_update(self.data, node_info)
     self.assertFalse(mock_patch.called)
 def setUp(self):
     super(TestValidateInterfacesHookBeforeUpdatePXEEnabled, self).setUp()
     self.hook = std_plugins.ValidateInterfacesHook()
     # Note(milan) assumes the ordering of self.macs from test_base.NodeTest
     # where the first item '11:22:33:44:55:66' is the MAC of the
     # self.pxe_iface_name 'eth1', the "real" PXE interface
     sorted_interfaces = sorted(self.valid_interfaces.values(),
                                key=lambda i: i['mac'])
     self.existing_ports = [
         mock.Mock(spec=['address', 'uuid', 'pxe_enabled'],
                   address=iface['mac'], pxe_enabled=True)
         for iface in sorted_interfaces
     ]
     self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=0,
                                          node=self.node,
                                          ports=self.existing_ports)
 def test_add_attribute(self):
     session = db.get_session()
     with session.begin():
         db.Node(uuid=self.node.uuid).save(session)
     node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=42)
     node_info.add_attribute('key', 'value')
     res = db.model_query(db.Attribute.name,
                          db.Attribute.value,
                          db.Attribute.uuid,
                          session=session)
     res = res.order_by(db.Attribute.name, db.Attribute.value).all()
     self.assertEqual([('key', 'value', self.uuid)],
                      [tuple(row) for row in res])
     self.assertRaises(utils.Error, node_info.add_attribute, 'key', 'value')
     # check that .attributes got invalidated and reloaded
     self.assertEqual({'key': ['value']}, node_info.attributes)
Ejemplo n.º 10
0
    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.new_creds = ('user', 'password')

        self.cli.port.create.side_effect = self.ports
        self.cli.node.update.return_value = self.node
        self.cli.node.list_ports.return_value = []
    def setUp(self):
        super(TestNuageLocalLinkConnectionHook, self).setUp()
        self.data = {
            'inventory': {
                'interfaces': [{
                    'name':
                    'enp2s0',
                    'mac_address':
                    '0c:c4:7a:4a:f1:82',
                    'ipv4_address':
                    '192.168.10.12',
                    'lldp':
                    [(0, ''), (1, '046854ed016d00'), (2, '073337383437303430'),
                     (3, '0079'), (4, '312d4769672045746865726e657420534650'),
                     (5, '7673672d69726f6e6963'), (7, '00140014'),
                     (8, '05010a1efe020200000001280000000100000003000000'
                      '060000000100000004000000010000197f000000010000'
                      '001200000001')]
                }],
                'cpu':
                1,
                'disks':
                1,
                'memory':
                1
            },
            'all_interfaces': {
                'enp2s0': {},
            }
        }

        llc = {'port_id': '56'}

        ports = [
            mock.Mock(spec=['address', 'uuid', 'local_link_connection'],
                      address=a,
                      local_link_connection=llc)
            for a in ('0c:c4:7a:4a:f1:82', )
        ]
        self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                             started_at=0,
                                             node=self.node,
                                             ports=ports)
Ejemplo n.º 12
0
    def setUp(self):
        super(TestValidateInterfacesHook, self).setUp()
        self.hook = std_plugins.ValidateInterfacesHook()
        self.data = {
            'interfaces': {
                'em1': {
                    'mac': '11:11:11:11:11:11',
                    'ip': '1.1.1.1'
                },
                'em2': {
                    'mac': '22:22:22:22:22:22',
                    'ip': '2.2.2.2'
                },
                'em3': {
                    'mac': '33:33:33:33:33:33'
                }
            },
            'boot_interface': '01-22-22-22-22-22-22',
        }
        self.orig_interfaces = self.data['interfaces'].copy()
        self.pxe_interface = self.data['interfaces']['em2']
        self.active_interfaces = {
            'em1': {
                'mac': '11:11:11:11:11:11',
                'ip': '1.1.1.1'
            },
            'em2': {
                'mac': '22:22:22:22:22:22',
                'ip': '2.2.2.2'
            },
        }

        self.existing_ports = [
            mock.Mock(spec=['address', 'uuid'], address=a)
            for a in ('11:11:11:11:11:11', '44:44:44:44:44:44')
        ]
        self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                             started_at=0,
                                             node=self.node,
                                             ports=self.existing_ports)
Ejemplo n.º 13
0
    def setUp(self):
        super(TestSystemNameLocalLinkConnectionHook, self).setUp()
        self.data = {
            'inventory': {
                'interfaces': [{
                    'name':
                    'em1',
                    'mac_address':
                    '11:11:11:11:11:11',
                    'ipv4_address':
                    '1.1.1.1',
                    'lldp': [
                        (0, ''),
                        (5, '7377697463682d31')  # switch-1
                    ]
                }],
                'cpu':
                1,
                'disks':
                1,
                'memory':
                1
            },
            'all_interfaces': {
                'em1': {},
            }
        }

        llc = {'switch_info': 'switch-2'}

        ports = [
            mock.Mock(spec=['address', 'uuid', 'local_link_connection'],
                      address=a,
                      local_link_connection=llc)
            for a in ('11:11:11:11:11:11', )
        ]
        self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                             started_at=0,
                                             node=self.node,
                                             ports=ports)
Ejemplo n.º 14
0
    def setUp(self):
        super(BaseTest, self).setUp()
        self.uuid = 'uuid'
        self.conditions_json = [
            {
                'op': 'eq',
                'field': 'memory_mb',
                'value': 1024
            },
            {
                'op': 'eq',
                'field': 'local_gb',
                'value': 60
            },
        ]
        self.actions_json = [{'action': 'fail', 'message': 'boom!'}]

        self.data = {
            'memory_mb': 1024,
            'local_gb': 42,
        }
        self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=42)
Ejemplo n.º 15
0
    def setUp(self):
        super(TestBasePortPhysnetHook, self).setUp()
        self.data = {
            'inventory': {
                'interfaces': [{
                    'name': 'em1', 'mac_address': '11:11:11:11:11:11',
                    'ipv4_address': '1.1.1.1',
                }],
                'cpu': 1,
                'disks': 1,
                'memory': 1
            },
            'all_interfaces': {
                'em1': {},
            }
        }

        ports = [mock.Mock(spec=['address', 'uuid', 'physical_network'],
                           address=a, physical_network='physnet1')
                 for a in ('11:11:11:11:11:11',)]
        self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=0,
                                             node=self.node, ports=ports)
Ejemplo n.º 16
0
 def setUp(self):
     super(NodeTest, self).setUp()
     self.uuid = '1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e'
     self.bmc_address = '1.2.3.4'
     self.macs = ['11:22:33:44:55:66', '66:55:44:33:22:11']
     self.node = mock.Mock(driver='pxe_ipmitool',
                           driver_info={'ipmi_address': self.bmc_address},
                           properties={
                               'cpu_arch': 'i386',
                               'local_gb': 40
                           },
                           uuid=self.uuid,
                           power_state='power on',
                           provision_state='inspecting',
                           extra={},
                           instance_uuid=None,
                           maintenance=False)
     self.ports = []
     self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                          started_at=0,
                                          node=self.node,
                                          ports=self.ports)
    def setUp(self):
        super(TestGenericLocalLinkConnectionHook, self).setUp()
        self.data = {
            'inventory': {
                'interfaces': [{
                    'name':
                    'em1',
                    'mac_address':
                    '11:11:11:11:11:11',
                    'ipv4_address':
                    '1.1.1.1',
                    'lldp': [(0, ''), (1, '04885a92ec5459'),
                             (2, '0545746865726e6574312f3138'), (3, '0078')]
                }],
                'cpu':
                1,
                'disks':
                1,
                'memory':
                1
            },
            'all_interfaces': {
                'em1': {},
            }
        }

        llc = {'port_id': '56'}

        ports = [
            mock.Mock(spec=['address', 'uuid', 'local_link_connection'],
                      address=a,
                      local_link_connection=llc)
            for a in ('11:11:11:11:11:11', )
        ]
        self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                             started_at=0,
                                             node=self.node,
                                             ports=ports)
Ejemplo n.º 18
0
    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.port.create.side_effect = self.ports
        self.cli.node.update.return_value = self.node
        self.cli.node.list_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)
Ejemplo n.º 19
0
 def setUp(self):
     super(TestSchedulerHook, self).setUp()
     self.hook = std_plugins.SchedulerHook()
     self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                          started_at=0,
                                          node=self.node)
 def test_ports_provided_list(self, mock_ironic):
     node_info = node_cache.NodeInfo(uuid=self.uuid,
                                     started_at=0,
                                     ports=list(self.ports.values()))
     self.assertEqual(self.ports, node_info.ports())
     self.assertFalse(mock_ironic.called)
 def test_ports_provided(self, mock_ironic):
     node_info = node_cache.NodeInfo(uuid=self.uuid,
                                     started_at=0,
                                     ports=self.ports)
     self.assertIs(self.ports, node_info.ports())
     self.assertFalse(mock_ironic.called)
 def test_node_provided(self, mock_ironic):
     node_info = node_cache.NodeInfo(uuid=self.uuid,
                                     started_at=0,
                                     node=mock.sentinel.node)
     self.assertIs(mock.sentinel.node, node_info.node())
     self.assertFalse(mock_ironic.called)
Ejemplo n.º 23
0
 def wrapper(self, pop_mock, *args, **kw):
     pop_mock.return_value = node_cache.NodeInfo(
         uuid=self.node.uuid, started_at=self.started_at)
     pop_mock.return_value.finished = mock.Mock()
     pop_mock.return_value.acquire_lock = mock.Mock()
     return func(self, pop_mock, *args, **kw)
Ejemplo n.º 24
0
 def test_prefix_NodeInfo_instance_with_state(self):
     node_info = node_cache.NodeInfo('NNN', state='foobar')
     self.assertEqual('[node: NNN state foobar]',
                      utils.processing_logger_prefix(node_info=node_info))
Ejemplo n.º 25
0
 def test_prefix_NodeInfo_instance(self):
     node_info = node_cache.NodeInfo('NNN')
     self.assertEqual('[node: NNN]',
                      utils.processing_logger_prefix(node_info=node_info))