def forwards_func(apps, schema_editor): Worker = apps.get_model("lava_scheduler_app", "Worker") db_alias = schema_editor.connection.alias # Identify master node and populate the required fields. # Since migrations run only on master node, we assume the current node # should be designated as master. is_master = True localhost = utils.get_fqdn() ipaddr = utils.get_ip_address() # NOTE: RPC2_URL formed below is a guess. The administrator should # revisit the correctness of this URL from the administration # UI, fixing it for the node which is designated as the master. rpc2_url = "http://{0}/RPC2".format(localhost) if localhost == 'example.com' or localhost == 'www.example.com': rpc2_url = "http://{0}/RPC2".format(ipaddr) try: with transaction.atomic(): worker, created = Worker.objects.using(db_alias).get_or_create( hostname=localhost) worker.is_master = is_master worker.ip_address = ipaddr worker.rpc2_url = rpc2_url worker.save() except: print "Identifying master node failed ..."
def forwards(self, orm): # Deleting field 'Worker.heartbeat' db.delete_column('lava_scheduler_app_worker', 'heartbeat') # Adding field 'Worker.rpc2_url' db.add_column('lava_scheduler_app_worker', 'rpc2_url', self.gf('django.db.models.fields.CharField')( default=None, max_length=200, null=True, blank=True), keep_default=False) # Adding field 'Worker.ip_address' db.add_column('lava_scheduler_app_worker', 'ip_address', self.gf('django.db.models.fields.CharField')( default=None, max_length=20, null=True, blank=True), keep_default=False) # Adding field 'Worker.is_master' db.add_column( 'lava_scheduler_app_worker', 'is_master', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False) # Deleting field 'Device.heartbeat' db.delete_column('lava_scheduler_app_device', 'heartbeat') # Deleting field 'Device.last_heartbeat' db.delete_column('lava_scheduler_app_device', 'last_heartbeat') # Identify master node and populate the required fields. # Since migrations run only on master node, we assume the current node # should be designated as master. is_master = True localhost = utils.get_fqdn() ipaddr = utils.get_ip_address() # NOTE: RPC2_URL formed below is a guess. The administrator should # revisit the correctness of this URL from the administration # UI, fixing it for the node which is designated as the master. rpc2_url = "http://{0}/RPC2".format(localhost) if localhost == 'example.com' or localhost == 'www.example.com': rpc2_url = "http://{0}/RPC2".format(ipaddr) try: worker = orm['lava_scheduler_app.Worker'].objects.get( hostname=localhost) worker.is_master = is_master worker.ip_address = ipaddr worker.rpc2_url = rpc2_url except: worker = orm['lava_scheduler_app.Worker'](hostname=localhost, ip_address=ipaddr, is_master=is_master, rpc2_url=rpc2_url) worker.save()
def populate_minimal_worker_data(self): """This method populates the minimal information about the worker node. """ self.worker["info_size"] = "minimal" self.worker["hostname"] = utils.get_fqdn() self.worker["uptime"] = utils.get_uptime() self.worker["devices"] = [x.hostname for x in dispatcher_config.get_devices()] self.logger.debug("Minimal worker data populated ...")
def populate_minimal_worker_data(self): """This method populates the minimal information about the worker node. """ self.worker['info_size'] = 'minimal' self.worker['hostname'] = utils.get_fqdn() self.worker['uptime'] = utils.get_uptime() self.worker['devices'] = [ x.hostname for x in dispatcher_config.get_devices() ] self.logger.debug("Minimal worker data populated ...")
def forwards(self, orm): # Deleting field 'Worker.heartbeat' db.delete_column('lava_scheduler_app_worker', 'heartbeat') # Adding field 'Worker.rpc2_url' db.add_column('lava_scheduler_app_worker', 'rpc2_url', self.gf('django.db.models.fields.CharField')(default=None, max_length=200, null=True, blank=True), keep_default=False) # Adding field 'Worker.ip_address' db.add_column('lava_scheduler_app_worker', 'ip_address', self.gf('django.db.models.fields.CharField')(default=None, max_length=20, null=True, blank=True), keep_default=False) # Adding field 'Worker.is_master' db.add_column('lava_scheduler_app_worker', 'is_master', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False) # Deleting field 'Device.heartbeat' db.delete_column('lava_scheduler_app_device', 'heartbeat') # Deleting field 'Device.last_heartbeat' db.delete_column('lava_scheduler_app_device', 'last_heartbeat') # Identify master node and populate the required fields. # Since migrations run only on master node, we assume the current node # should be designated as master. is_master = True localhost = utils.get_fqdn() ipaddr = utils.get_ip_address() # NOTE: RPC2_URL formed below is a guess. The administrator should # revisit the correctness of this URL from the administration # UI, fixing it for the node which is designated as the master. rpc2_url = "http://{0}/RPC2".format(localhost) if localhost == 'example.com' or localhost == 'www.example.com': rpc2_url = "http://{0}/RPC2".format(ipaddr) try: worker = orm['lava_scheduler_app.Worker'].objects.get( hostname=localhost) worker.is_master = is_master worker.ip_address = ipaddr worker.rpc2_url = rpc2_url except: worker = orm['lava_scheduler_app.Worker'](hostname=localhost, ip_address=ipaddr, is_master=is_master, rpc2_url=rpc2_url) worker.save()
def put_heartbeat_data(self, restart=False): """Puts heartbeat data via the xmlrpc api. If the scheduler daemon was restarted identified by RESTART, populate the complete worker data, else populate minimal worker data, if it is too long since the last heartbeat data was updated. """ try: localhost = Worker.localhost() if localhost.too_long_since_last_heartbeat(): self.populate_minimal_worker_data() elif restart: self.populate_complete_worker_data() else: return except ValueError: self.logger.debug("Worker %s unavailable" % utils.get_fqdn()) self.populate_complete_worker_data() MAX_RETRIES = 3 data = simplejson.dumps(self.worker) for retry in range(MAX_RETRIES): try: server = _get_scheduler_rpc() server.worker_heartbeat(data) self.logger.debug("Heartbeat updated") return except (CommandError, URLError, IOError) as err: self.logger.debug("Error message: %s" % str(err)) except xmlrpclib.Fault as err: time.sleep(1) self.logger.debug("Retrying heartbeat update (%d) ..." % retry) except xmlrpclib.ProtocolError as err: self.logger.error("Protocol error occured") self.logger.error("URL: %s" % err.url) self.logger.error("HTTP/HTTPS headers: %s" % err.headers) self.logger.error("Error code: %d" % err.errcode) self.logger.error("Error message: %s" % err.errmsg) raise err self.logger.error("Unable to update the Heartbeat, trying later")
def put_heartbeat_data(self, restart=False): """Puts heartbeat data via the xmlrpc api. If the scheduler daemon was restarted identified by RESTART, populate the complete worker data, else populate minimal worker data, if it is too long since the last heartbeat data was updated. """ try: localhost = Worker.localhost() if restart: self.populate_complete_worker_data() elif localhost.too_long_since_last_heartbeat(): self.populate_minimal_worker_data() else: return except ValueError: self.logger.debug("Worker %s unavailable", utils.get_fqdn()) self.populate_complete_worker_data() MAX_RETRIES = 3 data = simplejson.dumps(self.worker) for retry in range(MAX_RETRIES): try: server = _get_scheduler_rpc() server.worker_heartbeat(data) self.logger.debug("Heartbeat updated") return except (CommandError, URLError, IOError) as err: self.logger.debug("Error message: %s", str(err)) except xmlrpclib.Fault as err: time.sleep(1) self.logger.debug("Retrying heartbeat update (%d) ...", retry) except xmlrpclib.ProtocolError as err: self.logger.error("Protocol error occured") self.logger.error("URL: %s", err.url) self.logger.error("HTTP/HTTPS headers: %s", err.headers) self.logger.error("Error code: %d", err.errcode) self.logger.error("Error message: %s", err.errmsg) raise err self.logger.error("Unable to update the Heartbeat, trying later")
"testdef_repos": [ { "git-repo": "REPO_PARAMETER", "testdef": "TESTDEF_PARAMETER" } ] } LAVA_TEST_SHELL_URL = { "testdef_urls": "TESTDEF_URLS_PARAMETER" } COMMAND_SUBMIT_RESULTS = { "command": "submit_results", "parameters": { "server": "http://{0}/RPC2".format(utils.get_fqdn()), "stream": "BUNDLE_STREAM" } } COMMAND_TEST_SHELL = { "command": "lava_test_shell", "parameters": "TEST_SHELL_PARAMETER", } ACTIONS_LINARO_ANDROID_IMAGE = [ { "command": "deploy_linaro_android_image", "parameters": { "boot": "BOOT_IMAGE_PARAMETER", "data": "DATA_IMAGE_PARAMETER",