예제 #1
0
    def test_bmc(self, client_mock, filters_mock):
        self.node.driver_info['ipmi_address'] = '1.2.3.4'
        cli = client_mock.return_value
        cli.node.list.return_value = [
            Mock(driver_info={}),
            Mock(driver_info={'ipmi_address': '4.3.2.1'}),
            self.node,
            Mock(driver_info={'ipmi_address': '1.2.1.2'}),
        ]
        cli.port.create.side_effect = [None, exceptions.Conflict()]

        self.data['ipmi_address'] = '1.2.3.4'
        discoverd.process(self.data)

        self.assertTrue(cli.node.list.called)
        self.assertFalse(cli.port.get_by_address.called)
        cli.node.update.assert_called_once_with(self.node.uuid, self.patch)
        cli.port.create.assert_any_call(node_uuid=self.node.uuid,
                                        address='11:22:33:44:55:66')
        cli.port.create.assert_any_call(node_uuid=self.node.uuid,
                                        address='66:55:44:33:22:11')
        self.assertEqual(2, cli.port.create.call_count)
        filters_mock.assert_called_once_with(cli)
        self.assertEqual(set(), discoverd.Firewall.MACS_DISCOVERY)
        cli.node.set_power_state.assert_called_once_with(self.node.uuid, 'off')
예제 #2
0
 def test_retry_on_conflict_fail(self):
     call = mock.Mock()
     call.side_effect = ([exceptions.Conflict()] * (utils.RETRY_COUNT + 1)
                         + [mock.sentinel.result])
     self.assertRaises(exceptions.Conflict, utils.retry_on_conflict,
                       call, 1, 2, x=3)
     call.assert_called_with(1, 2, x=3)
     self.assertEqual(utils.RETRY_COUNT, call.call_count)
예제 #3
0
 def test_retry_on_conflict(self):
     call = mock.Mock()
     call.side_effect = ([exceptions.Conflict()] * (utils.RETRY_COUNT - 1)
                         + [mock.sentinel.result])
     res = utils.retry_on_conflict(call, 1, 2, x=3)
     self.assertEqual(mock.sentinel.result, res)
     call.assert_called_with(1, 2, x=3)
     self.assertEqual(utils.RETRY_COUNT, call.call_count)
예제 #4
0
    def test_port_failed(self):
        self.cli.port.create.side_effect = ([exceptions.Conflict()] +
                                            self.ports[1:])

        process._process_node(self.node, self.data, self.node_info)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0])
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1])
    def test_port_failed(self, filters_mock, post_hook_mock):
        self.cli.port.create.side_effect = ([exceptions.Conflict()] +
                                            self.ports[1:])

        self.call()

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0])
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1])
        self.assertCalledWithPatch(self.patch_props, self.cli.node.update)
예제 #6
0
    def test_port_failed(self):
        self.cli.port.create.side_effect = (
            [exceptions.Conflict()] + self.ports[1:])

        process._process_node(self.node_info, self.node, self.data)

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0],
                                             extra={}, pxe_enabled=True)
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1],
                                             extra={}, pxe_enabled=False)
예제 #7
0
    def test_port_failed(self, filters_mock, post_hook_mock):
        self.ports[0] = exceptions.Conflict()

        self.call()

        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[0])
        self.cli.port.create.assert_any_call(node_uuid=self.uuid,
                                             address=self.macs[1])
        self.cli.node.update.assert_any_call(self.uuid, self.patch_before)
        self.cli.node.update.assert_any_call(self.uuid, self.patch_after)

        post_hook_mock.assert_called_once_with(self.node, self.ports[1:],
                                               self.data)
예제 #8
0
    def test(self, client_mock, filters_mock):
        cli = client_mock.return_value
        cli.node.get.side_effect = [
            exceptions.NotFound(),
            self.node1,
            exceptions.Conflict(),
            self.node2,
        ]
        cli.node.list_ports.return_value = [Mock(address='1'),
                                            Mock(address='2')]

        discoverd.discover(['uuid%d' % i for i in range(4)])

        self.assertEqual(4, cli.node.get.call_count)
        cli.node.list_ports.assert_called_once_with('uuid1', limit=0)
        filters_mock.assert_called_once_with(cli)
        self.assertEqual(set(['1', '2']), discoverd.Firewall.MACS_DISCOVERY)
        self.assertEqual(2, cli.node.set_power_state.call_count)
        cli.node.set_power_state.assert_called_with(ANY, 'on')
        patch = [{'op': 'add', 'path': '/extra/on_discovery', 'value': 'true'}]
        cli.node.update.assert_any_call('uuid1', patch)
        cli.node.update.assert_any_call('uuid3', patch)
        self.assertEqual(2, cli.node.update.call_count)
예제 #9
0
    def test_macs(self, client_mock, filters_mock):
        discoverd.ALLOW_SEARCH_BY_MAC = True
        cli = client_mock.return_value
        cli.port.get_by_address.side_effect = [
            exceptions.NotFound(), Mock(node_uuid=self.node.uuid)]
        cli.port.create.side_effect = [None, exceptions.Conflict()]
        cli.node.get.return_value = self.node

        discoverd.process(self.data)

        self.assertFalse(cli.node.list.called)
        cli.port.get_by_address.assert_any_call('11:22:33:44:55:66')
        cli.port.get_by_address.assert_any_call('66:55:44:33:22:11')
        cli.node.get.assert_called_once_with(self.node.uuid)
        cli.node.update.assert_called_once_with(self.node.uuid, self.patch)
        cli.port.create.assert_any_call(node_uuid=self.node.uuid,
                                        address='11:22:33:44:55:66')
        cli.port.create.assert_any_call(node_uuid=self.node.uuid,
                                        address='66:55:44:33:22:11')
        self.assertEqual(2, cli.port.create.call_count)
        filters_mock.assert_called_once_with(cli)
        self.assertEqual(set(), discoverd.Firewall.MACS_DISCOVERY)
        cli.node.set_power_state.assert_called_once_with(self.node.uuid, 'off')