Exemple #1
0
 def test_register_all_nodes_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(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')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
 def test_register_all_nodes_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(node_list, client=ironic,
                              glance_client=glance, kernel_name='bm-kernel',
                              ramdisk_name='bm-ramdisk')
     pxe_node_driver_info = {"ipmi_address": "foo.bar",
                             "ipmi_username": "******",
                             "ipmi_password": "******",
                             "deploy_kernel": "kernel-123",
                             "deploy_ramdisk": "ramdisk-999"}
     pxe_node = mock.call(driver="ipmi",
                          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')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
Exemple #3
0
 def test_register_all_nodes_caps_dict(self):
     node_list = [self._get_node()]
     node_list[0]['capabilities'] = {'num_nics': 7}
     node_properties = {
         "cpus": "1",
         "memory_mb": "2048",
         "local_gb": "30",
         "cpu_arch": "amd64",
         "capabilities": "num_nics:7"
     }
     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_caps_dict(self):
     node_list = [self._get_node()]
     node_list[0]['capabilities'] = {'num_nics': 7}
     node_properties = {
         "cpus": "1",
         "memory_mb": "2048",
         "local_gb": "30",
         "cpu_arch": "amd64",
         "capabilities": "num_nics:7"
     }
     ironic = mock.MagicMock()
     nodes.register_all_nodes(node_list, client=ironic)
     pxe_node_driver_info = {
         "ipmi_address": "foo.bar",
         "ipmi_username": "******",
         "ipmi_password": "******"
     }
     pxe_node = mock.call(driver="ipmi",
                          name='node1',
                          driver_info=pxe_node_driver_info,
                          resource_class='baremetal',
                          properties=node_properties)
     port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                           address='aaa')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
Exemple #5
0
    def test_register_all_nodes_with_interfaces(self):
        interfaces = {'boot_interface': 'pxe',
                      'console_interface': 'ipmitool-socat',
                      'deploy_interface': 'direct',
                      'inspect_interface': 'inspector',
                      'management_interface': 'ipmitool',
                      'network_interface': 'neutron',
                      'power_interface': 'ipmitool',
                      'raid_interface': 'agent',
                      'storage_interface': 'cinder',
                      'vendor_interface': 'ipmitool'}

        node_list = [self._get_node()]
        node_list[0].update(interfaces)
        node_properties = {"cpus": "1",
                           "memory_mb": "2048",
                           "local_gb": "30",
                           "cpu_arch": "amd64",
                           "capabilities": "num_nics:6"}
        ironic = mock.MagicMock()
        nodes.register_all_nodes(node_list, client=ironic)
        pxe_node_driver_info = {"ipmi_address": "foo.bar",
                                "ipmi_username": "******",
                                "ipmi_password": "******"}
        pxe_node = mock.call(driver="ipmi",
                             name='node1',
                             driver_info=pxe_node_driver_info,
                             properties=node_properties,
                             resource_class='baremetal',
                             **interfaces)
        port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                              address='aaa', physical_network='ctlplane')
        ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
        ironic.port.create.assert_has_calls([port_call])
Exemple #6
0
 def test_register_all_nodes_uuid(self):
     node_list = [self._get_node()]
     node_list[0]['uuid'] = 'abcdef'
     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,
                          uuid="abcdef")
     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_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()
        new_nodes = nodes.register_all_nodes(node_list, client=ironic)
        self.assertEqual([ironic.node.create.return_value], new_nodes)
        pxe_node_driver_info = {"ipmi_address": "foo.bar",
                                "ipmi_username": "******",
                                "ipmi_password": "******"}
        pxe_node = mock.call(driver="ipmi",
                             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')
        ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
        ironic.port.create.assert_has_calls([port_call])
Exemple #8
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()
        new_nodes = nodes.register_all_nodes('servicehost',
                                             node_list,
                                             client=ironic)
        self.assertEqual([ironic.node.create.return_value], new_nodes)
        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_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()
        new_nodes = nodes.register_all_nodes(node_list, client=ironic)
        self.assertEqual([ironic.node.create.return_value], new_nodes)
        pxe_node_driver_info = {
            "ipmi_address": "foo.bar",
            "ipmi_username": "******",
            "ipmi_password": "******"
        }
        pxe_node = mock.call(driver="ipmi",
                             name='node1',
                             driver_info=pxe_node_driver_info,
                             resource_class='baremetal',
                             properties=node_properties)
        port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
                              address='aaa')
        ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
        ironic.port.create.assert_has_calls([port_call])
    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']

        client = self.app.client_manager.baremetal
        if parsed_args.initial_state == "enroll":
            api_version = client.http_client.os_ironic_api_version
            if [int(part) for part in api_version.split('.')] < [1, 11]:
                raise exceptions.InvalidConfiguration(
                    _("OS_BAREMETAL_API_VERSION must be >=1.11 for use of "
                      "'enroll' provision state; currently %s") % api_version)

        for node in nodes_config:
            caps = utils.capabilities_to_dict(node.get('capabilities', {}))
            caps.setdefault('boot_option', parsed_args.instance_boot_option)
            node['capabilities'] = utils.dict_to_capabilities(caps)

        new_nodes = nodes.register_all_nodes(
            parsed_args.service_host,
            nodes_config,
            client=client,
            keystone_client=self.app.client_manager.identity,
            glance_client=self.app.client_manager.image,
            kernel_name=(parsed_args.deploy_kernel
                         if not parsed_args.no_deploy_image else None),
            ramdisk_name=(parsed_args.deploy_ramdisk
                          if not parsed_args.no_deploy_image else None))

        if parsed_args.initial_state == "available":
            manageable_node_uuids = list(
                utils.set_nodes_state(
                    client,
                    new_nodes,
                    "manage",
                    "manageable",
                    skipped_states={'manageable', 'available'}))
            manageable_nodes = [
                n for n in new_nodes if n.uuid in manageable_node_uuids
            ]
            list(
                utils.set_nodes_state(client,
                                      manageable_nodes,
                                      "provide",
                                      "available",
                                      skipped_states={'available'}))
 def test_register_all_nodes(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(node_list, client=ironic)
     pxe_node_driver_info = {"ipmi_address": "foo.bar",
                             "ipmi_username": "******",
                             "ipmi_password": "******"}
     pxe_node = mock.call(driver="ipmi",
                          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')
     ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
     ironic.port.create.assert_has_calls([port_call])
    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']

        client = self.app.client_manager.baremetal
        if parsed_args.initial_state == "enroll":
            api_version = client.http_client.os_ironic_api_version
            if [int(part) for part in api_version.split('.')] < [1, 11]:
                raise exceptions.InvalidConfiguration(
                    _("OS_BAREMETAL_API_VERSION must be >=1.11 for use of "
                      "'enroll' provision state; currently %s") % api_version)

        for node in nodes_config:
            caps = utils.capabilities_to_dict(node.get('capabilities', {}))
            caps.setdefault('boot_option', parsed_args.instance_boot_option)
            node['capabilities'] = utils.dict_to_capabilities(caps)

        new_nodes = nodes.register_all_nodes(
            parsed_args.service_host,
            nodes_config,
            client=client,
            keystone_client=self.app.client_manager.identity,
            glance_client=self.app.client_manager.image,
            kernel_name=(parsed_args.deploy_kernel if not
                         parsed_args.no_deploy_image else None),
            ramdisk_name=(parsed_args.deploy_ramdisk if not
                          parsed_args.no_deploy_image else None))

        if parsed_args.initial_state == "available":
            manageable_node_uuids = list(utils.set_nodes_state(
                client, new_nodes, "manage", "manageable",
                skipped_states={'manageable', 'available'}
            ))
            manageable_nodes = [
                n for n in new_nodes if n.uuid in manageable_node_uuids
            ]
            list(utils.set_nodes_state(
                client, manageable_nodes, "provide", "available",
                skipped_states={'available'}
            ))
def run_module():
    result = dict(success=False, error="", nodes=[])

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])

    module = AnsibleModule(argument_spec,
                           supports_check_mode=True,
                           **openstack_module_kwargs())

    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)

    # if the user is working with this module in only check mode we do not
    # want to make any changes to the environment, just return the current
    # state with no modifications
    if module.check_mode:
        module.exit_json(**result)

    nodes_json = nodes.convert_nodes_json_mac_to_ports(
        module.params['nodes_json'])

    for node in nodes_json:
        caps = node.get('capabilities', {})
        caps = nodes.capabilities_to_dict(caps)
        if module.params['instance_boot_option'] is not None:
            caps.setdefault('boot_option',
                            module.params['instance_boot_option'])
        node['capabilities'] = nodes.dict_to_capabilities(caps)

    baremetal_client = tripleo.get_baremetal_client()
    image_client = tripleo.get_image_client()

    try:
        registered_nodes = nodes.register_all_nodes(
            nodes_json,
            client=baremetal_client,
            remove=module.params['remove'],
            glance_client=image_client,
            kernel_name=module.params['kernel_name'],
            ramdisk_name=module.params['ramdisk_name'])
        result['success'] = True
        result['nodes'] = [
            dict(uuid=node.uuid, provision_state=node.provision_state)
            for node in registered_nodes
        ]
    except Exception as exc:
        # LOG.exception("Error registering nodes with ironic.")
        result['error'] = str(exc)
        module.fail_json(msg='Validation Failed', **result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
Exemple #14
0
    def run(self, context):
        for node in self.nodes_json:
            caps = node.get('capabilities', {})
            caps = nodes.capabilities_to_dict(caps)
            caps.setdefault('boot_option', self.instance_boot_option)
            node['capabilities'] = nodes.dict_to_capabilities(caps)

        baremetal_client = self.get_baremetal_client(context)
        image_client = self.get_image_client(context)

        try:
            return nodes.register_all_nodes(self.nodes_json,
                                            client=baremetal_client,
                                            remove=self.remove,
                                            glance_client=image_client,
                                            kernel_name=self.kernel_name,
                                            ramdisk_name=self.ramdisk_name)
        except Exception as err:
            LOG.exception("Error registering nodes with ironic.")
            return actions.Result(error=six.text_type(err))
    def run(self, context):
        for node in self.nodes_json:
            caps = node.get('capabilities', {})
            caps = nodes.capabilities_to_dict(caps)
            caps.setdefault('boot_option', self.instance_boot_option)
            node['capabilities'] = nodes.dict_to_capabilities(caps)

        baremetal_client = self.get_baremetal_client(context)
        image_client = self.get_image_client(context)

        try:
            return nodes.register_all_nodes(
                self.nodes_json,
                client=baremetal_client,
                remove=self.remove,
                glance_client=image_client,
                kernel_name=self.kernel_name,
                ramdisk_name=self.ramdisk_name)
        except Exception as err:
            LOG.exception("Error registering nodes with ironic.")
            return actions.Result(error=six.text_type(err))
Exemple #16
0
    def run(self):
        for node in self.nodes_json:
            caps = node.get('capabilities', {})
            caps = nodes.capabilities_to_dict(caps)
            caps.setdefault('boot_option', self.instance_boot_option)
            node['capabilities'] = nodes.dict_to_capabilities(caps)

        baremetal_client = self._get_baremetal_client()
        image_client = self._get_image_client()

        try:
            return nodes.register_all_nodes(
                'service_host',  # unused
                self.nodes_json,
                client=baremetal_client,
                remove=self.remove,
                glance_client=image_client,
                kernel_name=self.kernel_name,
                ramdisk_name=self.ramdisk_name)
        except Exception as err:
            LOG.exception("Error registering nodes with ironic.")
            return mistral_workflow_utils.Result("", err.message)