def setUp(self):
     super(TestNodeCacheFind, self).setUp()
     self.macs2 = ['00:00:00:00:00:00']
     node_cache.add_node(self.uuid,
                         istate.States.starting,
                         bmc_address='1.2.3.4',
                         mac=self.macs)
示例#2
0
    def test_update_filters_args(self, mock_call, mock_get_client,
                                 mock_iptables):
        # Pretend that we have nodes on introspection
        node_cache.add_node(self.node.uuid,
                            state=istate.States.waiting,
                            bmc_address='1.2.3.4')

        firewall.init()

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN), ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN), ('-N', firewall.NEW_CHAIN),
            ('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        firewall.update_filters()
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args, call_args_list):
            self.assertEqual(args, call[0])
 def setUp(self):
     super(TestNodeCacheFind, self).setUp()
     self.macs2 = ['00:00:00:00:00:00']
     node_cache.add_node(self.uuid,
                         istate.States.starting,
                         bmc_address='1.2.3.4',
                         mac=self.macs)
 def setUp(self):
     super(TestNodeInfoOptions, self).setUp()
     node_cache.add_node(self.uuid, bmc_address='1.2.3.4', mac=self.macs)
     self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=3.14)
     session = db.get_session()
     with session.begin():
         db.Option(uuid=self.uuid, name='foo', value='"bar"').save(session)
    def test_update_filters_args(self, mock_call, mock_get_client,
                                 mock_iptables):
        # Pretend that we have nodes on introspection
        node_cache.add_node(self.node.uuid, state=istate.States.waiting,
                            bmc_address='1.2.3.4')

        firewall.init()

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', firewall.NEW_CHAIN),
            ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN),
            ('-N', firewall.NEW_CHAIN),
            ('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        firewall.update_filters()
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args,
                                call_args_list):
            self.assertEqual(args, call[0])
 def test_same_bmc_different_macs(self):
     uuid2 = uuidutils.generate_uuid()
     node_cache.add_node(uuid2,
                         istate.States.starting,
                         bmc_address='1.2.3.4',
                         mac=self.macs2)
     res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs)
     self.assertEqual(self.uuid, res.uuid)
     res = node_cache.find_node(bmc_address='1.2.3.4', mac=self.macs2)
     self.assertEqual(uuid2, res.uuid)
 def test_same_bmc_raises(self):
     uuid2 = uuidutils.generate_uuid()
     node_cache.add_node(uuid2,
                         istate.States.starting,
                         bmc_address='1.2.3.4')
     six.assertRaisesRegex(self,
                           utils.Error,
                           'Multiple nodes',
                           node_cache.find_node,
                           bmc_address='1.2.3.4')
 def setUp(self):
     super(TestNodeInfoOptions, self).setUp()
     node_cache.add_node(self.uuid,
                         bmc_address='1.2.3.4',
                         mac=self.macs)
     self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=3.14)
     session = db.get_session()
     with session.begin():
         db.Option(uuid=self.uuid, name='foo', value='"bar"').save(
             session)
 def setUp(self):
     super(TestNodeInfoFinished, self).setUp()
     node_cache.add_node(self.uuid,
                         istate.States.processing,
                         bmc_address='1.2.3.4',
                         mac=self.macs)
     self.node_info = node_cache.NodeInfo(
         uuid=self.uuid, started_at=datetime.datetime(3, 1, 4))
     session = db.get_session()
     with session.begin():
         db.Option(uuid=self.uuid, name='foo', value='bar').save(
             session)
    def test_update_filters_args_no_introspection(self, mock_call,
                                                  mock_get_client,
                                                  mock_iptables):
        firewall.init()
        firewall.BLACKLIST_CACHE = ['foo']
        mock_get_client.return_value.port.list.return_value = [
            mock.Mock(address='foobar')]

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', firewall.NEW_CHAIN),
            ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN),
            ('-N', firewall.NEW_CHAIN),
            ('-A', firewall.NEW_CHAIN, '-j', 'REJECT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        firewall.update_filters()
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args,
                                call_args_list):
            self.assertEqual(args, call[0])

        self.assertIsNone(firewall.BLACKLIST_CACHE)

        # Check caching enabled flag

        mock_iptables.reset_mock()
        firewall.update_filters()
        self.assertFalse(mock_iptables.called)

        # Adding a node changes it back

        node_cache.add_node(self.node.uuid, state=istate.States.starting,
                            bmc_address='1.2.3.4')
        mock_iptables.reset_mock()
        firewall.update_filters()

        mock_iptables.assert_any_call('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT')
        self.assertEqual({'foobar'}, firewall.BLACKLIST_CACHE)
 def setUp(self):
     super(TestNodeInfoFinished, self).setUp()
     node_cache.add_node(self.uuid,
                         istate.States.processing,
                         bmc_address='1.2.3.4',
                         mac=self.macs)
     self.node_info = node_cache.NodeInfo(uuid=self.uuid,
                                          started_at=datetime.datetime(
                                              3, 1, 4))
     session = db.get_session()
     with session.begin():
         db.Option(uuid=self.uuid, name='foo', value='bar').save(session)
示例#12
0
    def test_update_filters_args_no_introspection(self, mock_call,
                                                  mock_get_client,
                                                  mock_iptables):
        firewall.init()
        firewall.BLACKLIST_CACHE = ['foo']
        mock_get_client.return_value.port.list.return_value = [
            mock.Mock(address='foobar')
        ]

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN), ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN), ('-N', firewall.NEW_CHAIN),
            ('-A', firewall.NEW_CHAIN, '-j', 'REJECT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        firewall.update_filters()
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args, call_args_list):
            self.assertEqual(args, call[0])

        self.assertIsNone(firewall.BLACKLIST_CACHE)

        # Check caching enabled flag

        mock_iptables.reset_mock()
        firewall.update_filters()
        self.assertFalse(mock_iptables.called)

        # Adding a node changes it back

        node_cache.add_node(self.node.uuid,
                            state=istate.States.starting,
                            bmc_address='1.2.3.4')
        mock_iptables.reset_mock()
        firewall.update_filters()

        mock_iptables.assert_any_call('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT')
        self.assertEqual({'foobar'}, firewall.BLACKLIST_CACHE)
示例#13
0
    def test_update_filters_infiniband(self, mock_call, mock_get_client,
                                       mock_iptables):

        CONF.set_override('ethoib_interfaces', ['eth0'], 'firewall')
        active_macs = ['11:22:33:44:55:66', '66:55:44:33:22:11']
        expected_rmac = '02:00:00:61:00:02'
        ports = [mock.Mock(address=m) for m in active_macs]
        ports.append(
            mock.Mock(address='7c:fe:90:29:24:4f',
                      extra={'client-id': self.CLIENT_ID},
                      spec=['address', 'extra']))
        mock_get_client.port.list.return_value = ports
        node_cache.add_node(self.node.uuid,
                            mac=active_macs,
                            state=istate.States.finished,
                            bmc_address='1.2.3.4',
                            foo=None)
        firewall.init()

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN),
            ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN),
            ('-N', firewall.NEW_CHAIN),
            # Blacklist
            ('-A', firewall.NEW_CHAIN, '-m', 'mac', '--mac-source',
             expected_rmac, '-j', 'DROP'),
            ('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        fileobj = mock.mock_open(read_data=IB_DATA)
        with mock.patch('six.moves.builtins.open', fileobj, create=True):
            firewall.update_filters(mock_get_client)
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args, call_args_list):
            self.assertEqual(args, call[0])
示例#14
0
    def test_update_filters_with_blacklist(self, mock_call, mock_get_client,
                                           mock_iptables):
        active_macs = ['11:22:33:44:55:66', '66:55:44:33:22:11']
        inactive_mac = ['AA:BB:CC:DD:EE:FF']
        self.macs = active_macs + inactive_mac
        self.ports = [mock.Mock(address=m) for m in self.macs]
        mock_get_client.port.list.return_value = self.ports
        node_cache.add_node(self.node.uuid,
                            mac=active_macs,
                            state=istate.States.finished,
                            bmc_address='1.2.3.4',
                            foo=None)
        firewall.init()

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN),
            ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN),
            ('-N', firewall.NEW_CHAIN),
            # Blacklist
            ('-A', firewall.NEW_CHAIN, '-m', 'mac', '--mac-source',
             inactive_mac[0], '-j', 'DROP'),
            ('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        firewall.update_filters(mock_get_client)
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args, call_args_list):
            self.assertEqual(args, call[0])

        # check caching

        mock_iptables.reset_mock()
        firewall.update_filters(mock_get_client)
        self.assertFalse(mock_iptables.called)
    def test_update_filters_with_blacklist(self, mock_call, mock_get_client,
                                           mock_iptables):
        active_macs = ['11:22:33:44:55:66', '66:55:44:33:22:11']
        inactive_mac = ['AA:BB:CC:DD:EE:FF']
        self.macs = active_macs + inactive_mac
        self.ports = [mock.Mock(address=m) for m in self.macs]
        mock_get_client.port.list.return_value = self.ports
        node_cache.add_node(self.node.uuid, mac=active_macs,
                            state=istate.States.finished,
                            bmc_address='1.2.3.4', foo=None)
        firewall.init()

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', firewall.NEW_CHAIN),
            ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN),
            ('-N', firewall.NEW_CHAIN),
            # Blacklist
            ('-A', firewall.NEW_CHAIN, '-m', 'mac', '--mac-source',
             inactive_mac[0], '-j', 'DROP'),
            ('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport',
             '67', '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        firewall.update_filters(mock_get_client)
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args,
                                call_args_list):
            self.assertEqual(args, call[0])

        # check caching

        mock_iptables.reset_mock()
        firewall.update_filters(mock_get_client)
        self.assertFalse(mock_iptables.called)
示例#16
0
    def test_add_node(self):
        # Ensure previous node information is cleared
        session = db.get_session()
        with session.begin():
            db.Node(uuid=self.node.uuid).save(session)
            db.Node(uuid='uuid2').save(session)
            db.Attribute(name='mac',
                         value='11:22:11:22:11:22',
                         uuid=self.uuid).save(session)

        res = node_cache.add_node(self.node.uuid, mac=self.macs,
                                  bmc_address='1.2.3.4', foo=None)
        self.assertEqual(self.uuid, res.uuid)
        self.assertTrue(time.time() - 60 < res.started_at < time.time() + 60)
        self.assertFalse(res._locked)

        res = (db.model_query(db.Node.uuid,
               db.Node.started_at).order_by(db.Node.uuid).all())
        self.assertEqual(['1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e',
                          'uuid2'], [t.uuid for t in res])
        self.assertTrue(time.time() - 60 < res[0].started_at <
                        time.time() + 60)

        res = (db.model_query(db.Attribute.name,
                              db.Attribute.value, db.Attribute.uuid).
               order_by(db.Attribute.name, db.Attribute.value).all())
        self.assertEqual([('bmc_address', '1.2.3.4', self.uuid),
                          ('mac', self.macs[0], self.uuid),
                          ('mac', self.macs[1], self.uuid)],
                         [(row.name, row.value, row.uuid) for row in res])
    def test_add_node(self):
        # Ensure previous node information is cleared
        uuid2 = uuidutils.generate_uuid()
        session = db.get_session()
        with session.begin():
            db.Node(uuid=self.node.uuid).save(session)
            db.Node(uuid=uuid2).save(session)
            db.Attribute(name='mac', value='11:22:11:22:11:22',
                         uuid=self.uuid).save(session)

        node = node_cache.add_node(self.node.uuid,
                                   mac=self.macs,
                                   bmc_address='1.2.3.4',
                                   foo=None)
        self.assertEqual(self.uuid, node.uuid)
        self.assertTrue(time.time() - 60 < node.started_at < time.time() + 60)
        self.assertFalse(node._locked)

        res = set(db.model_query(db.Node.uuid, db.Node.started_at).all())

        expected = {(node.uuid, node.started_at), (uuid2, None)}
        self.assertEqual(expected, res)

        res = (db.model_query(db.Attribute.name, db.Attribute.value,
                              db.Attribute.uuid).order_by(
                                  db.Attribute.name, db.Attribute.value).all())
        self.assertEqual([('bmc_address', '1.2.3.4', self.uuid),
                          ('mac', self.macs[0], self.uuid),
                          ('mac', self.macs[1], self.uuid)],
                         [(row.name, row.value, row.uuid) for row in res])
示例#18
0
    def test_add_node(self):
        # Ensure previous node information is cleared
        session = db.get_session()
        with session.begin():
            db.Node(uuid=self.node.uuid).save(session)
            db.Node(uuid='uuid2').save(session)
            db.Attribute(name='mac',
                         value='11:22:11:22:11:22',
                         uuid=self.uuid).save(session)

        res = node_cache.add_node(self.node.uuid, mac=self.macs,
                                  bmc_address='1.2.3.4', foo=None)
        self.assertEqual(self.uuid, res.uuid)
        self.assertTrue(time.time() - 60 < res.started_at < time.time() + 60)

        res = (db.model_query(db.Node.uuid,
               db.Node.started_at).order_by(db.Node.uuid).all())
        self.assertEqual(['1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e',
                          'uuid2'], [t.uuid for t in res])
        self.assertTrue(time.time() - 60 < res[0].started_at <
                        time.time() + 60)

        res = (db.model_query(db.Attribute.name,
                              db.Attribute.value, db.Attribute.uuid).
               order_by(db.Attribute.name, db.Attribute.value).all())
        self.assertEqual([('bmc_address', '1.2.3.4', self.uuid),
                          ('mac', self.macs[0], self.uuid),
                          ('mac', self.macs[1], self.uuid)],
                         [(row.name, row.value, row.uuid) for row in res])
 def test_attributes(self):
     node_info = node_cache.add_node(self.uuid,
                                     istate.States.starting,
                                     bmc_address='1.2.3.4',
                                     mac=self.macs)
     self.assertEqual({
         'bmc_address': ['1.2.3.4'],
         'mac': self.macs
     }, node_info.attributes)
     # check invalidation
     session = db.get_session()
     with session.begin():
         db.Attribute(uuid=uuidutils.generate_uuid(),
                      name='foo',
                      value='bar',
                      node_uuid=self.uuid).save(session)
     # still cached
     self.assertEqual({
         'bmc_address': ['1.2.3.4'],
         'mac': self.macs
     }, node_info.attributes)
     node_info.invalidate_cache()
     self.assertEqual(
         {
             'bmc_address': ['1.2.3.4'],
             'mac': self.macs,
             'foo': ['bar']
         }, node_info.attributes)
    def test_add_node(self):
        # Ensure previous node information is cleared
        uuid2 = uuidutils.generate_uuid()
        session = db.get_session()
        with session.begin():
            db.Node(uuid=self.node.uuid).save(session)
            db.Node(uuid=uuid2).save(session)
            db.Attribute(name='mac',
                         value='11:22:11:22:11:22',
                         uuid=self.uuid).save(session)

        node = node_cache.add_node(self.node.uuid, mac=self.macs,
                                   bmc_address='1.2.3.4', foo=None)
        self.assertEqual(self.uuid, node.uuid)
        self.assertTrue(time.time() - 60 < node.started_at < time.time() + 60)
        self.assertFalse(node._locked)

        res = set(db.model_query(db.Node.uuid,
                                 db.Node.started_at).all())

        expected = {(node.uuid, node.started_at), (uuid2, None)}
        self.assertEqual(expected, res)

        res = (db.model_query(db.Attribute.name,
                              db.Attribute.value, db.Attribute.uuid).
               order_by(db.Attribute.name, db.Attribute.value).all())
        self.assertEqual([('bmc_address', '1.2.3.4', self.uuid),
                          ('mac', self.macs[0], self.uuid),
                          ('mac', self.macs[1], self.uuid)],
                         [(row.name, row.value, row.uuid) for row in res])
def hook(introspection_data, **kwargs):
    ironic = utils.get_client()
    try:
        node = ironic.node.create(**{'driver': 'fake'})
    except exceptions.HttpError as exc:
        raise utils.Error(_("Can not create node in ironic for unknown"
                            "node: %s") % exc)
    return node_cache.add_node(node.uuid, ironic=ironic)
示例#22
0
    def test_update_filters_args_no_introspection(self, mock_call,
                                                  mock_get_client,
                                                  mock_iptables):
        firewall.init()

        update_filters_expected_args = [
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-N', CONF.firewall.firewall_chain),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN), ('-F', firewall.NEW_CHAIN),
            ('-X', firewall.NEW_CHAIN), ('-N', firewall.NEW_CHAIN),
            ('-A', firewall.NEW_CHAIN, '-j', 'REJECT'),
            ('-I', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', firewall.NEW_CHAIN),
            ('-D', 'INPUT', '-i', 'br-ctlplane', '-p', 'udp', '--dport', '67',
             '-j', CONF.firewall.firewall_chain),
            ('-F', CONF.firewall.firewall_chain),
            ('-X', CONF.firewall.firewall_chain),
            ('-E', firewall.NEW_CHAIN, CONF.firewall.firewall_chain)
        ]

        firewall.update_filters()
        call_args_list = mock_iptables.call_args_list

        for (args, call) in zip(update_filters_expected_args, call_args_list):
            self.assertEqual(args, call[0])

        # Check caching enabled flag

        mock_iptables.reset_mock()
        firewall.update_filters()
        self.assertFalse(mock_iptables.called)

        # Adding a node changes it back

        node_cache.add_node(self.node.uuid, bmc_address='1.2.3.4')
        mock_iptables.reset_mock()
        firewall.update_filters()

        mock_iptables.assert_any_call('-A', firewall.NEW_CHAIN, '-j', 'ACCEPT')
示例#23
0
def introspect(uuid, new_ipmi_credentials=None, token=None):
    """Initiate hardware properties introspection for a given node.

    :param uuid: node uuid
    :param new_ipmi_credentials: tuple (new username, new password) or None
    :param token: authentication token
    :raises: Error
    """
    ironic = utils.get_client(token)

    try:
        node = ironic.node.get(uuid)
    except exceptions.NotFound:
        raise utils.Error(_("Cannot find node %s") % uuid, code=404)
    except exceptions.HttpError as exc:
        raise utils.Error(
            _("Cannot get node %(node)s: %(exc)s") % {
                'node': uuid,
                'exc': exc
            })

    utils.check_provision_state(node, with_credentials=new_ipmi_credentials)

    if new_ipmi_credentials:
        new_ipmi_credentials = (_validate_ipmi_credentials(
            node, new_ipmi_credentials))
    else:
        validation = ironic.node.validate(node.uuid)
        if not validation.power['result']:
            msg = _('Failed validation of power interface for node %(node)s, '
                    'reason: %(reason)s')
            raise utils.Error(msg % {
                'node': node.uuid,
                'reason': validation.power['reason']
            })

    node_info = node_cache.add_node(node.uuid,
                                    bmc_address=utils.get_ipmi_address(node),
                                    ironic=ironic)
    node_info.set_option('new_ipmi_credentials', new_ipmi_credentials)

    def _handle_exceptions():
        try:
            _background_introspect(ironic, node_info)
        except utils.Error as exc:
            node_info.finished(error=str(exc))
        except Exception as exc:
            msg = _('Unexpected exception in background introspection thread')
            LOG.exception(msg)
            node_info.finished(error=msg)

    utils.spawn_n(_handle_exceptions)
示例#24
0
def introspect(uuid, new_ipmi_credentials=None, token=None):
    """Initiate hardware properties introspection for a given node.

    :param uuid: node uuid
    :param new_ipmi_credentials: tuple (new username, new password) or None
    :param token: authentication token
    :raises: Error
    """
    ironic = ir_utils.get_client(token)

    try:
        node = ironic.node.get(uuid)
    except exceptions.NotFound:
        raise utils.Error(_("Cannot find node %s") % uuid, code=404)
    except exceptions.HttpError as exc:
        raise utils.Error(
            _("Cannot get node %(node)s: %(exc)s") % {
                'node': uuid,
                'exc': exc
            })

    ir_utils.check_provision_state(node, with_credentials=new_ipmi_credentials)

    if new_ipmi_credentials:
        new_ipmi_credentials = (_validate_ipmi_credentials(
            node, new_ipmi_credentials))
    else:
        validation = ironic.node.validate(node.uuid)
        if not validation.power['result']:
            msg = _('Failed validation of power interface, reason: %s')
            raise utils.Error(msg % validation.power['reason'], node_info=node)

    bmc_address = ir_utils.get_ipmi_address(node)
    node_info = node_cache.add_node(node.uuid,
                                    bmc_address=bmc_address,
                                    ironic=ironic)
    node_info.set_option('new_ipmi_credentials', new_ipmi_credentials)

    def _handle_exceptions(fut):
        try:
            fut.result()
        except utils.Error as exc:
            # Logging has already happened in Error.__init__
            node_info.finished(error=str(exc))
        except Exception as exc:
            msg = _('Unexpected exception in background introspection thread')
            LOG.exception(msg, node_info=node_info)
            node_info.finished(error=msg)

    future = utils.executor().submit(_background_introspect, ironic, node_info)
    future.add_done_callback(_handle_exceptions)
def introspect(uuid, new_ipmi_credentials=None, token=None):
    """Initiate hardware properties introspection for a given node.

    :param uuid: node uuid
    :param new_ipmi_credentials: tuple (new username, new password) or None
    :param token: authentication token
    :raises: Error
    """
    ironic = ir_utils.get_client(token)

    try:
        node = ironic.node.get(uuid)
    except exceptions.NotFound:
        raise utils.Error(_("Cannot find node %s") % uuid, code=404)
    except exceptions.HttpError as exc:
        raise utils.Error(_("Cannot get node %(node)s: %(exc)s") %
                          {'node': uuid, 'exc': exc})

    ir_utils.check_provision_state(node, with_credentials=new_ipmi_credentials)

    if new_ipmi_credentials:
        new_ipmi_credentials = (
            _validate_ipmi_credentials(node, new_ipmi_credentials))
    else:
        validation = ironic.node.validate(node.uuid)
        if not validation.power['result']:
            msg = _('Failed validation of power interface, reason: %s')
            raise utils.Error(msg % validation.power['reason'],
                              node_info=node)

    bmc_address = ir_utils.get_ipmi_address(node)
    node_info = node_cache.add_node(node.uuid,
                                    bmc_address=bmc_address,
                                    ironic=ironic)
    node_info.set_option('new_ipmi_credentials', new_ipmi_credentials)

    def _handle_exceptions(fut):
        try:
            fut.result()
        except utils.Error as exc:
            # Logging has already happened in Error.__init__
            node_info.finished(error=str(exc))
        except Exception as exc:
            msg = _('Unexpected exception in background introspection thread')
            LOG.exception(msg, node_info=node_info)
            node_info.finished(error=msg)

    future = utils.executor().submit(_background_introspect, ironic, node_info)
    future.add_done_callback(_handle_exceptions)
示例#26
0
def introspect(uuid, new_ipmi_credentials=None, token=None):
    """Initiate hardware properties introspection for a given node.

    :param uuid: node uuid
    :param new_ipmi_credentials: tuple (new username, new password) or None
    :param token: authentication token
    :raises: Error
    """
    ironic = utils.get_client(token)

    try:
        node = ironic.node.get(uuid)
    except exceptions.NotFound:
        raise utils.Error(_("Cannot find node %s") % uuid, code=404)
    except exceptions.HttpError as exc:
        raise utils.Error(_("Cannot get node %(node)s: %(exc)s") %
                          {'node': uuid, 'exc': exc})

    utils.check_provision_state(node, with_credentials=new_ipmi_credentials)

    if new_ipmi_credentials:
        new_ipmi_credentials = (
            _validate_ipmi_credentials(node, new_ipmi_credentials))
    else:
        validation = ironic.node.validate(node.uuid)
        if not validation.power['result']:
            msg = _('Failed validation of power interface for node %(node)s, '
                    'reason: %(reason)s')
            raise utils.Error(msg % {'node': node.uuid,
                                     'reason': validation.power['reason']})

    node_info = node_cache.add_node(node.uuid,
                                    bmc_address=utils.get_ipmi_address(node),
                                    ironic=ironic)
    node_info.set_option('new_ipmi_credentials', new_ipmi_credentials)

    def _handle_exceptions():
        try:
            _background_introspect(ironic, node_info)
        except utils.Error as exc:
            node_info.finished(error=str(exc))
        except Exception as exc:
            msg = _('Unexpected exception in background introspection thread')
            LOG.exception(msg)
            node_info.finished(error=msg)

    utils.spawn_n(_handle_exceptions)
 def test_attributes(self):
     node_info = node_cache.add_node(self.uuid,
                                     bmc_address='1.2.3.4',
                                     mac=self.macs)
     self.assertEqual({'bmc_address': ['1.2.3.4'],
                       'mac': self.macs},
                      node_info.attributes)
     # check invalidation
     session = db.get_session()
     with session.begin():
         db.Attribute(name='foo', value='bar', uuid=self.uuid).save(session)
     # still cached
     self.assertEqual({'bmc_address': ['1.2.3.4'],
                       'mac': self.macs},
                      node_info.attributes)
     node_info.invalidate_cache()
     self.assertEqual({'bmc_address': ['1.2.3.4'],
                       'mac': self.macs, 'foo': ['bar']},
                      node_info.attributes)
 def test_macs_multiple_found(self):
     node_cache.add_node('uuid2',
                         istate.States.starting,
                         mac=self.macs2)
     self.assertRaises(utils.Error, node_cache.find_node,
                       mac=[self.macs[0], self.macs2[0]])
 def test_macs_multiple_found(self):
     node_cache.add_node('uuid2', mac=self.macs2)
     self.assertRaises(utils.Error,
                       node_cache.find_node,
                       mac=[self.macs[0], self.macs2[0]])