示例#1
0
    def test_register_all_nodes_ironic_no_hw_stats(self):
        node_list = [self._get_node()]

        # Remove the hardware stats from the node dictionary
        node_list[0].pop("cpu")
        node_list[0].pop("memory")
        node_list[0].pop("disk")
        node_list[0].pop("arch")

        # Node properties should be created with empty string values for the
        # hardware statistics
        node_properties = {"capabilities": "num_nics:6"}

        ironic = mock.MagicMock()
        nodes.register_all_nodes('servicehost', node_list, client=ironic)
        pxe_node_driver_info = {
            "ssh_address": "foo.bar",
            "ssh_username": "******",
            "ssh_key_contents": "random",
            "ssh_virt_type": "virsh"
        }
        pxe_node = mock.call(driver="pxe_ssh",
                             name='node1',
                             driver_info=pxe_node_driver_info,
                             properties=node_properties)
        port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                              address='aaa')
        power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
        ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
        ironic.port.create.assert_has_calls([port_call])
        ironic.node.set_power_state.assert_has_calls([power_off_call])
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        glance_client = _clients.get_glance_client()
        client = _clients.get_ironic_client()

        nodes.register_all_nodes(args.service_host,
                                 nodes_list,
                                 client=client,
                                 remove=args.remove,
                                 blocking=True,
                                 keystone_client=keystone_client,
                                 glance_client=glance_client,
                                 kernel_name=args.kernel_name,
                                 ramdisk_name=args.ramdisk_name)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
示例#3
0
 def test_register_all_nodes_ironic_kernel_ramdisk(self):
     node_list = [self._get_node()]
     node_properties = {"cpus": "1",
                        "memory_mb": "2048",
                        "local_gb": "30",
                        "cpu_arch": "amd64",
                        "capabilities": "num_nics:6"}
     ironic = mock.MagicMock()
     glance = mock.MagicMock()
     image = collections.namedtuple('image', ['id'])
     glance.images.find.side_effect = (image('kernel-123'),
                                       image('ramdisk-999'))
     nodes.register_all_nodes('servicehost', node_list, client=ironic,
                              glance_client=glance, kernel_name='bm-kernel',
                              ramdisk_name='bm-ramdisk')
     pxe_node_driver_info = {"ssh_address": "foo.bar",
                             "ssh_username": "******",
                             "ssh_key_contents": "random",
                             "ssh_virt_type": "virsh",
                             "deploy_kernel": "kernel-123",
                             "deploy_ramdisk": "ramdisk-999"}
     pxe_node = mock.call(driver="pxe_ssh",
                          name='node1',
                          driver_info=pxe_node_driver_info,
                          properties=node_properties)
     port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                           address='aaa')
     power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
     ironic.node.set_power_state.assert_has_calls([power_off_call])
 def test_register_all_nodes_ironic(self, using_ironic):
     node_list = [self._get_node(), self._get_node()]
     node_list[1]["pm_type"] = "ipmi"
     node_properties = {"cpus": "1",
                        "memory_mb": "2048",
                        "local_gb": "30",
                        "cpu_arch": "amd64"}
     ironic = mock.MagicMock()
     nodes.register_all_nodes('servicehost', node_list, client=ironic)
     pxe_node_driver_info = {"ssh_address": "foo.bar",
                             "ssh_username": "******",
                             "ssh_key_contents": "random",
                             "ssh_virt_type": "virsh"}
     ipmi_node_driver_info = {"ipmi_address": "foo.bar",
                              "ipmi_username": "******",
                              "ipmi_password": "******"}
     pxe_node = mock.call(driver="pxe_ssh",
                          driver_info=pxe_node_driver_info,
                          properties=node_properties)
     port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                           address='aaa')
     power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
     ipmi_node = mock.call(driver="ipmi",
                           driver_info=ipmi_node_driver_info,
                           properties=node_properties)
     ironic.node.create.assert_has_calls([pxe_node, ipmi_node])
     ironic.port.create.assert_has_calls([port_call, port_call])
     ironic.node.set_power_state.assert_has_calls(
         [power_off_call, power_off_call])
示例#5
0
 def test_register_all_nodes_ironic(self):
     node_list = [self._get_node()]
     node_properties = {
         "cpus": "1",
         "memory_mb": "2048",
         "local_gb": "30",
         "cpu_arch": "amd64",
         "capabilities": "num_nics:6"
     }
     ironic = mock.MagicMock()
     nodes.register_all_nodes('servicehost', node_list, client=ironic)
     pxe_node_driver_info = {
         "ssh_address": "foo.bar",
         "ssh_username": "******",
         "ssh_key_contents": "random",
         "ssh_virt_type": "virsh"
     }
     pxe_node = mock.call(driver="pxe_ssh",
                          name='node1',
                          driver_info=pxe_node_driver_info,
                          properties=node_properties)
     port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                           address='aaa')
     power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
     ironic.node.set_power_state.assert_has_calls([power_off_call])
示例#6
0
    def test_register_all_nodes_ironic_no_hw_stats(self):
        node_list = [self._get_node()]

        # Remove the hardware stats from the node dictionary
        node_list[0].pop("cpu")
        node_list[0].pop("memory")
        node_list[0].pop("disk")
        node_list[0].pop("arch")

        # Node properties should be created with empty string values for the
        # hardware statistics
        node_properties = {"capabilities": "num_nics:6"}

        ironic = mock.MagicMock()
        nodes.register_all_nodes('servicehost', node_list, client=ironic)
        pxe_node_driver_info = {"ssh_address": "foo.bar",
                                "ssh_username": "******",
                                "ssh_key_contents": "random",
                                "ssh_virt_type": "virsh"}
        pxe_node = mock.call(driver="pxe_ssh",
                             name='node1',
                             driver_info=pxe_node_driver_info,
                             properties=node_properties)
        port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                              address='aaa')
        power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
        ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
        ironic.port.create.assert_has_calls([port_call])
        ironic.node.set_power_state.assert_has_calls([power_off_call])
 def test_register_all_nodes_nova_bm(self, ironic_mock):
     node_list = [self._get_node(), self._get_node()]
     node_list[0]["mac"].append("bbb")
     client = mock.MagicMock()
     nodes.register_all_nodes('servicehost', node_list, client=client)
     nova_bm_call = mock.call(
         "servicehost", "1", "2048", "30", "aaa", pm_address="foo.bar",
         pm_user="******", pm_password="******")
     client.baremetal.create.has_calls([nova_bm_call, nova_bm_call])
     client.baremetal.add_interface.assert_called_once_with(mock.ANY, "bbb")
def main():
    args = parse_args()

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        utils._ensure_environment()

        # TODO(StevenK): Filter out registered nodes.
        nodes.register_all_nodes(args.service_host, nodes_list)
    except Exception as e:
        print(str(e))
        return 1
    return 0
 def test_register_all_nodes_nova_bm(self, ironic_mock):
     node_list = [self._get_node(), self._get_node()]
     node_list[0]["mac"].append("bbb")
     client = mock.MagicMock()
     nodes.register_all_nodes('servicehost', node_list, client=client)
     nova_bm_call = mock.call("servicehost",
                              "1",
                              "2048",
                              "30",
                              "aaa",
                              pm_address="foo.bar",
                              pm_user="******",
                              pm_password="******")
     client.baremetal.create.has_calls([nova_bm_call, nova_bm_call])
     client.baremetal.add_interface.assert_called_once_with(mock.ANY, "bbb")
    def take_action(self, parsed_args):

        self.log.debug("take_action(%s)" % parsed_args)

        # We need JSON or CSV to be specified, not both.
        if parsed_args.json == parsed_args.csv:
            print("ERROR: Either --json or --csv needs to be specified.",
                  file=sys.stderr)
            return

        if parsed_args.json is True:
            nodes_json = json.load(parsed_args.file_in)
        else:
            nodes_json = _csv_to_nodes_dict(parsed_args.file_in)

        nodes.register_all_nodes(
            parsed_args.service_host,
            nodes_json,
            client=self.app.client_manager.rdomanager_oscplugin.baremetal(),
            keystone_client=self.app.client_manager.identity)
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        if nodes.using_ironic(keystone=keystone_client):
            client = _clients.get_ironic_client()
        else:
            client = _clients.get_nova_bm_client()

        nodes.register_all_nodes(
            args.service_host, nodes_list, client=client, remove=args.remove)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
示例#12
0
    def take_action(self, parsed_args):

        self.log.debug("take_action(%s)" % parsed_args)

        # We need JSON or CSV to be specified, not both.
        if parsed_args.json == parsed_args.csv:
            print("ERROR: Either --json or --csv needs to be specified.",
                  file=sys.stderr)
            return

        if parsed_args.json is True:
            nodes_json = json.load(parsed_args.file_in)
            if 'nodes' in nodes_json:
                nodes_json = nodes_json['nodes']
        else:
            nodes_json = _csv_to_nodes_dict(parsed_args.file_in)

        nodes.register_all_nodes(
            parsed_args.service_host,
            nodes_json,
            client=self.app.client_manager.rdomanager_oscplugin.baremetal(),
            keystone_client=self.app.client_manager.identity)
示例#13
0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        glance_client = _clients.get_glance_client()
        client = _clients.get_ironic_client()

        nodes.register_all_nodes(
            args.service_host, nodes_list, client=client, remove=args.remove,
            blocking=True, keystone_client=keystone_client,
            glance_client=glance_client, kernel_name=args.kernel_name,
            ramdisk_name=args.ramdisk_name)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
示例#14
0
 def test_register_all_nodes_ironic_kernel_ramdisk(self):
     node_list = [self._get_node()]
     node_properties = {
         "cpus": "1",
         "memory_mb": "2048",
         "local_gb": "30",
         "cpu_arch": "amd64",
         "capabilities": "num_nics:6"
     }
     ironic = mock.MagicMock()
     glance = mock.MagicMock()
     image = collections.namedtuple('image', ['id'])
     glance.images.find.side_effect = (image('kernel-123'),
                                       image('ramdisk-999'))
     nodes.register_all_nodes('servicehost',
                              node_list,
                              client=ironic,
                              glance_client=glance,
                              kernel_name='bm-kernel',
                              ramdisk_name='bm-ramdisk')
     pxe_node_driver_info = {
         "ssh_address": "foo.bar",
         "ssh_username": "******",
         "ssh_key_contents": "random",
         "ssh_virt_type": "virsh",
         "deploy_kernel": "kernel-123",
         "deploy_ramdisk": "ramdisk-999"
     }
     pxe_node = mock.call(driver="pxe_ssh",
                          name='node1',
                          driver_info=pxe_node_driver_info,
                          properties=node_properties)
     port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                           address='aaa')
     power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
     ironic.node.set_power_state.assert_has_calls([power_off_call])
示例#15
0
    def take_action(self, parsed_args):

        self.log.debug("take_action(%s)" % parsed_args)

        if parsed_args.json or parsed_args.file_in.name.endswith('.json'):
            nodes_config = json.load(parsed_args.file_in)
        elif parsed_args.csv or parsed_args.file_in.name.endswith('.csv'):
            nodes_config = _csv_to_nodes_dict(parsed_args.file_in)
        elif parsed_args.file_in.name.endswith('.yaml'):
            nodes_config = yaml.safe_load(parsed_args.file_in)
        else:
            raise exceptions.InvalidConfiguration(
                _("Invalid file extension for %s, must be json, yaml or csv") %
                parsed_args.file_in.name)

        if 'nodes' in nodes_config:
            nodes_config = nodes_config['nodes']

        nodes.register_all_nodes(
            parsed_args.service_host,
            nodes_config,
            client=self.app.client_manager.baremetal,
            keystone_client=self.app.client_manager.identity)
示例#16
0
def main():
    args = parse_args()
    environment._configure_logging(args)

    try:
        with open(args.nodes, 'r') as node_file:
            nodes_list = json.load(node_file)
        environment._ensure()

        keystone_client = _clients.get_keystone_client()
        if nodes.using_ironic(keystone=keystone_client):
            client = _clients.get_ironic_client()
        else:
            client = _clients.get_nova_bm_client()

        nodes.register_all_nodes(args.service_host,
                                 nodes_list,
                                 client=client,
                                 remove=args.remove)
    except Exception:
        logging.exception("Unexpected error during command execution")
        return 1
    return 0
    def take_action(self, parsed_args):

        self.log.debug("take_action(%s)" % parsed_args)

        if parsed_args.json or parsed_args.file_in.name.endswith('.json'):
            nodes_config = json.load(parsed_args.file_in)
        elif parsed_args.csv or parsed_args.file_in.name.endswith('.csv'):
            nodes_config = _csv_to_nodes_dict(parsed_args.file_in)
        elif parsed_args.file_in.name.endswith('.yaml'):
            nodes_config = yaml.safe_load(parsed_args.file_in)
        else:
            raise exceptions.InvalidConfiguration(
                _("Invalid file extension for %s, must be json, yaml or csv") %
                parsed_args.file_in.name)

        if 'nodes' in nodes_config:
            nodes_config = nodes_config['nodes']

        nodes.register_all_nodes(
            parsed_args.service_host,
            nodes_config,
            client=self.app.client_manager.baremetal,
            keystone_client=self.app.client_manager.identity)
示例#18
0
 def test_register_all_nodes_ironic(self):
     node_list = [self._get_node()]
     node_properties = {"cpus": "1",
                        "memory_mb": "2048",
                        "local_gb": "30",
                        "cpu_arch": "amd64",
                        "capabilities": "num_nics:6"}
     ironic = mock.MagicMock()
     nodes.register_all_nodes('servicehost', node_list, client=ironic)
     pxe_node_driver_info = {"ssh_address": "foo.bar",
                             "ssh_username": "******",
                             "ssh_key_contents": "random",
                             "ssh_virt_type": "virsh"}
     pxe_node = mock.call(driver="pxe_ssh",
                          name='node1',
                          driver_info=pxe_node_driver_info,
                          properties=node_properties)
     port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                           address='aaa')
     power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
     ironic.node.set_power_state.assert_has_calls([power_off_call])
示例#19
0
 def test_register_all_nodes_ironic(self, using_ironic):
     node_list = [
         self._get_node(),
         self._get_node(),
         self._get_node(),
         self._get_node()
     ]
     node_list[1]["pm_type"] = "ipmi"
     node_list[2]["pm_type"] = "pxe_iboot"
     node_list[3]["pm_virt_type"] = "vbox"
     node_properties = {
         "cpus": "1",
         "memory_mb": "2048",
         "local_gb": "30",
         "cpu_arch": "amd64"
     }
     ironic = mock.MagicMock()
     nodes.register_all_nodes('servicehost', node_list, client=ironic)
     pxe_node_driver_info = {
         "ssh_address": "foo.bar",
         "ssh_username": "******",
         "ssh_key_contents": "random",
         "ssh_virt_type": "virsh"
     }
     ipmi_node_driver_info = {
         "ipmi_address": "foo.bar",
         "ipmi_username": "******",
         "ipmi_password": "******"
     }
     iboot_node_driver_info = {
         "iboot_address": "foo.bar",
         "iboot_username": "******",
         "iboot_password": "******"
     }
     pxe_node_driver_info_vbox = {
         "ssh_address": "foo.bar",
         "ssh_username": "******",
         "ssh_key_contents": "random",
         "ssh_virt_type": "vbox"
     }
     pxe_node = mock.call(driver="pxe_ssh",
                          driver_info=pxe_node_driver_info,
                          properties=node_properties)
     port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                           address='aaa')
     power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
     ipmi_node = mock.call(driver="ipmi",
                           driver_info=ipmi_node_driver_info,
                           properties=node_properties)
     iboot_node = mock.call(driver="pxe_iboot",
                            driver_info=iboot_node_driver_info,
                            properties=node_properties)
     pxe_vbox_node = mock.call(driver="pxe_ssh",
                               driver_info=pxe_node_driver_info_vbox,
                               properties=node_properties)
     ironic.node.create.assert_has_calls([
         pxe_node, mock.ANY, ipmi_node, mock.ANY, iboot_node, mock.ANY,
         pxe_vbox_node, mock.ANY
     ])
     ironic.port.create.assert_has_calls(
         [port_call, port_call, port_call, port_call])
     ironic.node.set_power_state.assert_has_calls(
         [power_off_call, power_off_call, power_off_call, power_off_call])