Ejemplo n.º 1
0
 def test_get_interface_no_ip_last(self, mock_execute):
     lines = _LO_DEVICE, _ETH_DEVICE_NO_IP
     out = self._build_out(lines)
     mock_execute.return_value = out, ''
     ip = utils.get_interface_ip(self.mac)
     self.assertIsNone(ip)
     mock_execute.assert_called_once_with(*self.cmd)
Ejemplo n.º 2
0
 def test_get_interface_ip(self, mock_execute):
     lines = _LO_DEVICE, _ETH_DEVICE, _DOCKER_DEVICE
     out = self._build_out(lines)
     mock_execute.return_value = out, ''
     ip = utils.get_interface_ip(self.mac)
     self.assertEqual('172.18.204.10', ip)
     mock_execute.assert_called_once_with(*self.cmd)
Ejemplo n.º 3
0
 def test_get_interface_no_mac(self, mock_execute):
     lines = _LO_DEVICE, _DOCKER_DEVICE
     out = self._build_out(lines)
     mock_execute.return_value = out, ""
     ip = utils.get_interface_ip(self.mac)
     self.assertIsNone(ip)
     mock_execute.assert_called_once_with(*self.cmd)
Ejemplo n.º 4
0
def main():
    """Script informs Ironic that bootstrap loading is done.

    There are three mandatory parameters in kernel command line.
    Ironic prepares these two:
    'api-url' - URL of Ironic API service,
    'deployment_id' - UUID of the node in Ironic.
    Passed from PXE boot loader:
    'BOOTIF' - MAC address of the boot interface,
    http://www.syslinux.org/wiki/index.php/SYSLINUX#APPEND_-
    Example: api_url=http://192.168.122.184:6385
    deployment_id=eeeeeeee-dddd-cccc-bbbb-aaaaaaaaaaaa
    BOOTIF=01-88-99-aa-bb-cc-dd
    """
    kernel_params = utils.parse_kernel_cmdline()
    api_url = kernel_params.get('api-url')
    deployment_id = kernel_params.get('deployment_id')
    if api_url is None or deployment_id is None:
        _process_error('Mandatory parameter ("api-url" or "deployment_id") is '
                       'missing.')

    bootif = kernel_params.get('BOOTIF')
    if bootif is None:
        _process_error('Cannot define boot interface, "BOOTIF" parameter is '
                       'missing.')

    # The leading `01-' denotes the device type (Ethernet) and is not a part of
    # the MAC address
    boot_mac = bootif[3:].replace('-', ':')
    for n in range(10):
        boot_ip = utils.get_interface_ip(boot_mac)
        if boot_ip is not None:
            break
        time.sleep(10)
    else:
        _process_error('Cannot find IP address of boot interface.')

    data = {
        "address": boot_ip,
        "status": "ready",
        "error_message": "no errors"
    }

    passthru = '%(api-url)s/v1/nodes/%(deployment_id)s/vendor_passthru' \
               '/pass_deploy_info' % {'api-url': api_url,
                                      'deployment_id': deployment_id}
    try:
        resp = requests.post(passthru,
                             data=json.dumps(data),
                             headers={
                                 'Content-Type': 'application/json',
                                 'Accept': 'application/json'
                             })
    except Exception as e:
        _process_error(str(e))

    if resp.status_code != 202:
        _process_error('Wrong status code %d returned from Ironic API' %
                       resp.status_code)
Ejemplo n.º 5
0
def main():
    """Script informs Ironic that bootstrap loading is done.

    There are three mandatory parameters in kernel command line.
    Ironic prepares these two:
    'api-url' - URL of Ironic API service,
    'deployment_id' - UUID of the node in Ironic.
    Passed from PXE boot loader:
    'BOOTIF' - MAC address of the boot interface,
    http://www.syslinux.org/wiki/index.php/SYSLINUX#APPEND_-
    Example: api_url=http://192.168.122.184:6385
    deployment_id=eeeeeeee-dddd-cccc-bbbb-aaaaaaaaaaaa
    BOOTIF=01-88-99-aa-bb-cc-dd
    """
    kernel_params = utils.parse_kernel_cmdline()
    api_url = kernel_params.get('api-url')
    deployment_id = kernel_params.get('deployment_id')
    if api_url is None or deployment_id is None:
        _process_error('Mandatory parameter ("api-url" or "deployment_id") is '
                       'missing.')

    bootif = kernel_params.get('BOOTIF')
    if bootif is None:
        _process_error('Cannot define boot interface, "BOOTIF" parameter is '
                       'missing.')

    # The leading `01-' denotes the device type (Ethernet) and is not a part of
    # the MAC address
    boot_mac = bootif[3:].replace('-', ':')
    for n in range(10):
        boot_ip = utils.get_interface_ip(boot_mac)
        if boot_ip is not None:
            break
        time.sleep(10)
    else:
        _process_error('Cannot find IP address of boot interface.')

    data = {"address": boot_ip,
            "status": "ready",
            "error_message": "no errors"}

    passthru = '%(api-url)s/v1/nodes/%(deployment_id)s/vendor_passthru' \
               '/heartbeat' % {'api-url': api_url,
                               'deployment_id': deployment_id}
    try:
        resp = requests.post(passthru, data=json.dumps(data),
                             headers={'Content-Type': 'application/json',
                                      'Accept': 'application/json'})
    except Exception as e:
        _process_error(str(e))

    if resp.status_code != 202:
        _process_error('Wrong status code %d returned from Ironic API' %
                       resp.status_code)
Ejemplo n.º 6
0
def main():
    """Script informs Ironic that bootstrap loading is done.

    There are three mandatory parameters in kernel command line.
    Ironic prepares these two:
    'api-url' - URL of Ironic API service,
    'deployment_id' - UUID of the node in Ironic.
    Passed from PXE boot loader:
    'BOOTIF' - MAC address of the boot interface,
    http://www.syslinux.org/wiki/index.php/SYSLINUX#APPEND_-
    Example: api_url=http://192.168.122.184:6385
    deployment_id=eeeeeeee-dddd-cccc-bbbb-aaaaaaaaaaaa
    BOOTIF=01-88-99-aa-bb-cc-dd
    """
    kernel_params = utils.parse_kernel_cmdline()
    api_url = kernel_params.get('api-url')
    deployment_id = kernel_params.get('deployment_id')
    if api_url is None or deployment_id is None:
        _process_error('Mandatory parameter ("api-url" or "deployment_id") is '
                       'missing.')

    bootif = kernel_params.get('BOOTIF')
    if bootif is None:
        _process_error('Cannot define boot interface, "BOOTIF" parameter is '
                       'missing.')

    # The leading `01-' denotes the device type (Ethernet) and is not a part of
    # the MAC address
    boot_mac = bootif[3:].replace('-', ':')
    for n in range(_GET_ADDR_MAX_ITERATION):
        boot_ip = utils.get_interface_ip(boot_mac)
        if boot_ip is not None:
            break
        time.sleep(_RETRY_INTERVAL)
    else:
        _process_error('Cannot find IP address of boot interface.')

    # NOTE(pas-ha) supporting only Ironic API >= 1.22 !!!
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'X-OpenStack-Ironic-API-Version': '1.22'
    }
    data = {"callback_url": "ssh://" + boot_ip}
    heartbeat = '{api_url}/v1/heartbeat/{uuid}'.format(api_url=api_url,
                                                       uuid=deployment_id)

    for attempt in range(_POST_CALLBACK_MAX_ITERATION):
        try:
            resp = requests.post(heartbeat,
                                 data=json.dumps(data),
                                 headers=headers)
        except Exception as e:
            error = str(e)
        else:
            if resp.status_code != 202:
                error = ('Wrong status code %d returned from Ironic API' %
                         resp.status_code)
            else:
                break
        time.sleep(_RETRY_INTERVAL)
    else:
        # executed only when whole for block was executed w/o breaks
        _process_error(error)