def test_activate_and_deactivate_bootloader(self): self._create_node() instance_type = { 'extra_specs': { 'baremetal:deploy_kernel_id': 'eeee', 'baremetal:deploy_ramdisk_id': 'ffff', } } self.instance['uuid'] = 'fake-uuid' self.mox.StubOutWithMock(self.driver.virtapi, 'instance_type_get') self.mox.StubOutWithMock(utils, 'write_to_file') self.mox.StubOutWithMock(utils, 'create_link_without_raise') self.mox.StubOutWithMock(utils, 'unlink_without_raise') self.mox.StubOutWithMock(utils, 'rmtree_without_raise') self.driver.virtapi.instance_type_get( self.context, self.instance['instance_type_id']).AndReturn( instance_type) # create the config file utils.write_to_file(mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink and link the 2 interfaces for i in range(2): utils.unlink_without_raise(mox.Or( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) utils.create_link_without_raise( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink all 2 interfaces, 4 images, and the config file for i in range(7): utils.unlink_without_raise(mox.Or( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) utils.rmtree_without_raise(mox.StrContains('fake-uuid')) self.mox.ReplayAll() # activate and deactivate the bootloader # and check the deployment task_state in the database row = db.bm_node_get(self.context, 1) self.assertTrue(row['deploy_key'] is None) self.driver.activate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertTrue(row['deploy_key'] is not None) self.driver.deactivate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertTrue(row['deploy_key'] is None) self.mox.VerifyAll()
def _wait_for_deploy(): """Called at an interval until the deployment completes.""" try: row = db.bm_node_get(context, node['id']) if instance['uuid'] != row.get('instance_uuid'): locals['error'] = _("Node associated with another instance" " while waiting for deploy of %s") raise loopingcall.LoopingCallDone() status = row.get('task_state') if (status == states.DEPLOYING and locals['started'] is False): LOG.info(_("PXE deploy started for instance %s") % instance['uuid']) locals['started'] = True elif status in (states.DEPLOYDONE, states.ACTIVE): LOG.info(_("PXE deploy completed for instance %s") % instance['uuid']) raise loopingcall.LoopingCallDone() elif status == states.DEPLOYFAIL: locals['error'] = _("PXE deploy failed for instance %s") except exception.NodeNotFound: locals['error'] = _("Baremetal node deleted while waiting " "for deployment of instance %s") if (CONF.pxe_deploy_timeout and timeutils.utcnow() > expiration): locals['error'] = _("Timeout reached while waiting for " "PXE deploy of instance %s") if locals['error']: raise loopingcall.LoopingCallDone()
def _wait_for_deploy(): """Called at an interval until the deployment completes.""" try: row = db.bm_node_get(context, node['id']) if instance['uuid'] != row.get('instance_uuid'): locals['error'] = _("Node associated with another instance" " while waiting for deploy of %s") raise loopingcall.LoopingCallDone() status = row.get('task_state') if (status == states.DEPLOYING and locals['started'] is False): LOG.info( _("PXE deploy started for instance %s") % instance['uuid']) locals['started'] = True elif status in (states.DEPLOYDONE, states.ACTIVE): LOG.info( _("PXE deploy completed for instance %s") % instance['uuid']) raise loopingcall.LoopingCallDone() elif status == states.DEPLOYFAIL: locals['error'] = _("PXE deploy failed for instance %s") except exception.NodeNotFound: locals['error'] = _("Baremetal node deleted while waiting " "for deployment of instance %s") if (CONF.pxe_deploy_timeout and timeutils.utcnow() > expiration): locals['error'] = _("Timeout reached while waiting for " "PXE deploy of instance %s") if locals['error']: raise loopingcall.LoopingCallDone()
def post(self, environ, start_response): LOG.info(_("post: environ=%s") % environ) inpt = environ['wsgi.input'] length = int(environ.get('CONTENT_LENGTH', 0)) x = inpt.read(length) q = dict(cgi.parse_qsl(x)) try: node_id = q['i'] deploy_key = q['k'] address = q['a'] port = q.get('p', '3260') iqn = q['n'] lun = q.get('l', '1') err_msg = q.get('e') except KeyError as e: start_response('400 Bad Request', [('Content-type', 'text/plain')]) return "parameter '%s' is not defined" % e if err_msg: LOG.error(_('Deploy agent error message: %s'), err_msg) context = ironic_context.get_admin_context() d = db.bm_node_get(context, node_id) if d['deploy_key'] != deploy_key: start_response('400 Bad Request', [('Content-type', 'text/plain')]) return 'key is not match' params = {'address': address, 'port': port, 'iqn': iqn, 'lun': lun, 'image_path': d['image_path'], 'pxe_config_path': d['pxe_config_path'], 'root_mb': int(d['root_mb']), 'swap_mb': int(d['swap_mb']), } # Restart worker, if needed if not self.worker.isAlive(): self.worker = Worker() self.worker.start() LOG.info(_("request is queued: node %(node_id)s, params %(params)s") % {'node_id': node_id, 'params': params}) QUEUE.put((node_id, params)) # Requests go to Worker.run() start_response('200 OK', [('Content-type', 'text/plain')]) return ''
def post(self, environ, start_response): LOG.info("post: environ=%s", environ) inpt = environ['wsgi.input'] length = int(environ.get('CONTENT_LENGTH', 0)) x = inpt.read(length) q = dict(cgi.parse_qsl(x)) try: node_id = q['i'] deploy_key = q['k'] address = q['a'] port = q.get('p', '3260') iqn = q['n'] lun = q.get('l', '1') err_msg = q.get('e') except KeyError as e: start_response('400 Bad Request', [('Content-type', 'text/plain')]) return "parameter '%s' is not defined" % e if err_msg: LOG.error(_('Deploy agent error message: %s'), err_msg) context = ironic_context.get_admin_context() d = db.bm_node_get(context, node_id) if d['deploy_key'] != deploy_key: start_response('400 Bad Request', [('Content-type', 'text/plain')]) return 'key is not match' params = { 'address': address, 'port': port, 'iqn': iqn, 'lun': lun, 'image_path': d['image_path'], 'pxe_config_path': d['pxe_config_path'], 'root_mb': int(d['root_mb']), 'swap_mb': int(d['swap_mb']), } # Restart worker, if needed if not self.worker.isAlive(): self.worker = Worker() self.worker.start() LOG.info("request is queued: node %s, params %s", node_id, params) QUEUE.put((node_id, params)) # Requests go to Worker.run() start_response('200 OK', [('Content-type', 'text/plain')]) return ''
def activate_node(self, context, node, instance): """Wait for Tilera deployment to complete.""" locals = {'error': '', 'started': False} try: row = db.bm_node_get(context, node['id']) if instance['uuid'] != row.get('instance_uuid'): locals['error'] = _("Node associated with another instance" " while waiting for deploy of %s") status = row.get('task_state') if (status == states.DEPLOYING and locals['started'] is False): LOG.info(_('Tilera deploy started for instance %s') % instance['uuid']) locals['started'] = True elif status in (states.DEPLOYDONE, states.BUILDING, states.ACTIVE): LOG.info(_("Tilera deploy completed for instance %s") % instance['uuid']) node_ip = node['pm_address'] user_data = instance['user_data'] try: self._iptables_set(node_ip, user_data) except Exception: self.deactivate_bootloader(context, node, instance) raise exception.NovaException(_("Node is " "unknown error state.")) elif status == states.DEPLOYFAIL: locals['error'] = _("Tilera deploy failed for instance %s") except exception.NodeNotFound: locals['error'] = _("Baremetal node deleted while waiting " "for deployment of instance %s") if locals['error']: raise exception.InstanceDeployFailure( locals['error'] % instance['uuid'])