def Trigger(tc): if len(tc.Nodes) > 0: n = tc.Nodes[0] common.PenctlGetTransitionPhaseStatus(n) common.SetNaplesModeOOB_Static(n, "5.5.4.1", "5.5.4.4/24") tc.before_reboot_status = common.PenctlGetTransitionPhaseStatus(n) #common.PenctlGetControllersStatus(n)[0] api.Logger.info("Going for first reboot") tc.TriggerResult = api.types.status.SUCCESS err = common.RebootHost(n) if err == api.types.status.FAILURE: tc.TriggerResult = api.types.status.FAILURE return api.types.status.FAILURE tc.after_first_reboot_status = common.PenctlGetTransitionPhaseStatus(n) api.Logger.info("The Status after first reboot is {}".format( tc.after_first_reboot_status)) #tc.controller_ip_penctl_after.append(common.PenctlGetControllersStatus(n)[0]) api.Logger.info("Going for second reboot") common.RebootHost(n) tc.after_second_reboot_status = common.PenctlGetTransitionPhaseStatus( n) api.Logger.info("The Status after second reboot is {}".format( tc.after_second_reboot_status)) return api.types.status.SUCCESS
def Trigger(tc): if len(tc.Nodes) > 0 : n = tc.Nodes[0] for i in range(0, len(tc.venice_ips)): common.PrepareDhcpConfig(tc.venice_ips[i]) common.SetupRemoteDhcp(n) common.ResetNMDState(n) common.RebootHost(n) common.SetNaplesModeOOB_Dynamic(n) time.sleep(10) api.Logger.info("NAPLES STATUS before reboot") tc.naples_status_before.append(common.PenctlGetTransitionPhaseStatus(n)) api.Logger.info("Controller IPs before reboot") tc.controller_ip_penctl_before.append(common.PenctlGetControllersStatus(n)[0]) common.RebootHost(n) api.Logger.info("NAPLES STATUS after reboot check every 5 seconds for 1 minute.") for j in range(0, 12): tc.naples_status_after.append(common.PenctlGetTransitionPhaseStatus(n)) tc.controller_ip_penctl_after.append(common.PenctlGetControllersStatus(n)[0]) time.sleep(5) return api.types.status.SUCCESS
def Trigger(tc): if len(tc.Nodes) > 0: n = tc.Nodes[0] for i in range(0, len(tc.venice_ips)): common.ResetNMDState(n) common.RebootHost(n) common.PrepareDhcpConfig(tc.venice_ips[i]) common.SetupRemoteDhcp(n) time.sleep(10) common.SetNaplesModeInband_Dynamic(n) tc.naples_status_before.append(common.PenctlGetTransitionPhaseStatus(n)) tc.controller_ip_penctl_before.append(common.PenctlGetControllersStatus(n)[0]) common.StopRemoteDhcp(n) common.RebootHost(n) tc.naples_status_after.append(common.PenctlGetTransitionPhaseStatus(n)) tc.controller_ip_penctl_after.append(common.PenctlGetControllersStatus(n)[0]) return api.types.status.SUCCESS
def Trigger(tc): for n in tc.Nodes: common.PrepareDhcpConfigNoControllers() common.SetupRemoteDhcp(n) time.sleep(10) common.SetNaplesModeOOB_Dynamic(n) tc.naples_status_after.append(common.PenctlGetTransitionPhaseStatus(n)) tc.controller_ip_penctl_after.append( common.PenctlGetControllersStatus(n)) return api.types.status.SUCCESS
def Trigger(tc): for n in tc.Nodes: common.ResetNMDState(n) common.RebootHost(n) common.PrepareDhcpConfig(tc.venice_ips[0]) common.SetupRemoteDhcp(n) time.sleep(10) common.SetNaplesModeOOB_Dynamic(n) tc.naples_status_before.append(common.PenctlGetTransitionPhaseStatus(n)) tc.controller_ip_penctl_before.append(common.PenctlGetControllersStatus(n)) common.PrepareDhcpConfig(tc.venice_ips[1]) common.SetupRemoteDhcp(n) common.RebootHost(n) tc.naples_status_after.append(common.PenctlGetTransitionPhaseStatus(n)) tc.controller_ip_penctl_after.append(common.PenctlGetControllersStatus(n)) return api.types.status.SUCCESS
def Trigger(tc): if len(tc.Nodes) > 0: n = tc.Nodes[0] common.PenctlGetTransitionPhaseStatus(n) common.SetNaplesModeInband_Static(n, "1.1.1.1","1.1.1.2/24") tc.before_reboot_status = common.PenctlGetTransitionPhaseStatus(n) #common.PenctlGetControllersStatus(n)[0] api.Logger.info("Going for first reboot.") common.RebootHost(n) tc.after_first_reboot_status = common.PenctlGetTransitionPhaseStatus(n) #tc.controller_ip_penctl_after.append(common.PenctlGetControllersStatus(n)[0]) api.Logger.info("Going for second reboot.") common.RebootHost(n) tc.after_second_reboot_status = common.PenctlGetTransitionPhaseStatus(n) return api.types.status.SUCCESS
def Trigger(tc): if len(tc.Nodes) > 0: n = tc.Nodes[0] for i in range(0, 6): ret = common.SetNaplesModeInband_Static(n, "2.2.2.1", "2.2.2.2/24") time.sleep(10) mode = common.PenctlGetTransitionPhaseStatus(n) if mode != "VENICE_UNREACHABLE": return api.types.status.FAILURE return api.types.status.SUCCESS
def Trigger(tc): if len(tc.Nodes) > 0 : n = tc.Nodes[0] common.SetNaplesModeInband_Dynamic(n) api.Logger.info("NAPLES STATUS before reboot") tc.naples_status_before.append(common.PenctlGetTransitionPhaseStatus(n)) api.Logger.info("Controller IPs before reboot") tc.controller_ip_penctl_before.append(common.PenctlGetControllersStatus(n)[0]) api.Logger.info("NAPLES STATUS after reboot check every 5 seconds for 1 minute.") for j in range(0, 5): tc.naples_status_after.append(common.PenctlGetTransitionPhaseStatus(n)) tc.controller_ip_penctl_after.append(common.PenctlGetControllersStatus(n)[0]) time.sleep(5) api.Logger.info("Going for Reboot.") common.RebootHost(n) tc.after_reboot_status = common.PenctlGetTransitionPhaseStatus(n) return api.types.status.SUCCESS
def Main(step): if GlobalOptions.skip_setup: #No mode switch required for skeip setup return api.types.status.SUCCESS req = api.Trigger_CreateExecuteCommandsRequest(serial = True) uuidMap = api.GetNaplesNodeUuidMap() nodes = api.GetNaplesHostnames() for n in nodes: # Touch a file to indicate to NMD that the current mode is emulation cmd = "touch /data/iota-emulation" api.Trigger_AddNaplesCommand(req, n, cmd) # Make sure console is enabled CreateConfigConsoleNoAuth() api.CopyToNaples(n, [NAPLES_CONFIG_SPEC_LOCAL], "") cmd = "mv /system-config.json /sysconfig/config0/system-config.json" api.Trigger_AddNaplesCommand(req, n, cmd) if common.PenctlGetModeStatus(n) != "NETWORK" or common.PenctlGetTransitionPhaseStatus(n) != "VENICE_REGISTRATION_DONE": api.Logger.info("Host [{}] is in HOST mode. Initiating mode change.".format(n)) ret = common.SetNaplesModeOOB_Static(n, "1.1.1.1", "1.1.1.2/24") if ret == None: return api.types.status.FAILURE #hack for now, need to set date cmd = "date -s '{}'".format(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")) api.Trigger_AddNaplesCommand(req, n, cmd) resp = api.Trigger(req) for cmd in resp.commands: api.PrintCommandResults(cmd) if cmd.exit_code != 0: return api.types.status.FAILURE num_retries = 60 reboot_nodes = [] while nodes: req = api.Trigger_CreateExecuteCommandsRequest(serial = True) for n in nodes: #hack for now, need to set date api.Logger.info("Checking Transition phase for node : %s" % n) check_state_cmd = "show naples --json" time.sleep(30) common.AddPenctlCommand(req, n, check_state_cmd) api.Trigger_AddNaplesCommand(req, n, "touch /data/no_watchdog") resp = api.Trigger(req) cmd = resp.commands[0] api.PrintCommandResults(cmd) if cmd.exit_code != 0: return api.types.status.FAILURE try: out = json.loads(cmd.stdout) except: api.Logger.error("Penctl output not in Json format {}".format(cmd.stdout)) return api.types.status.FAILURE if not hal_show_utils.IsNaplesForwardingModeClassic(n): api.Logger.info("Dataplane already in HOSTPIN mode. Skipping node [{}] for reboot.".format(n)) reboot_nodes.append(n) nodes.remove(n) elif out["status"]["transition-phase"] == "VENICE_UNREACHABLE": api.Logger.info("Reboot pending on node : %s" % n) reboot_nodes.append(n) nodes.remove(n) elif out["status"]["transition-phase"] == "VENICE_REGISTRATION_DONE": api.Logger.info("Node already transitioned : %s" % n) nodes.remove(n) else: api.Logger.info("Reboot not pending on node : %s" % n) time.sleep(1) num_retries = num_retries - 1 if num_retries == 0: api.Logger.error("Reboot pending state not transitioned complete on naples") return api.types.status.FAILURE ret = api.RestartNodes(reboot_nodes) if ret != api.types.status.SUCCESS: api.Logger.error("Node restart failed") return api.types.status.FAILURE req = api.Trigger_CreateExecuteCommandsRequest(serial = True) #enable_sshd = "system enable-sshd" #copy_key = "update ssh-pub-key -f ~/.ssh/id_rsa.pub" for n in api.GetNaplesHostnames(): #hack for now, need to set date cmd = "date -s '{}'".format(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")) api.Trigger_AddNaplesCommand(req, n, cmd) #common.AddPenctlCommand(req, n, enable_sshd) #common.AddPenctlCommand(req, n, copy_key) resp = api.Trigger(req) for cmd in resp.commands: api.PrintCommandResults(cmd) if cmd.exit_code != 0: result = api.types.status.FAILURE #Give some time for naples to admit to venice after mode switch #This is required for now as Iota is setting time manually to make TLS happy time.sleep(30) #Check whether naples has switch mode succesfully req = api.Trigger_CreateExecuteCommandsRequest(serial = False) for n in nodes: cmd = "cat /sysconfig/config0/app-start.conf | grep hostpin" api.Trigger_AddNaplesCommand(req, n, cmd) resp = api.Trigger(req) for cmd in resp.commands: api.PrintCommandResults(cmd) if cmd.exit_code != 0: api.Logger.error("Mode switch failed on node : {}".format(cmd.node_name)) result = api.types.status.FAILURE #Verify Agent in right mode. req = api.Trigger_CreateExecuteCommandsRequest(serial = False) for n in nodes: cmd = "curl localhost:8888/api/system/info/" api.Trigger_AddNaplesCommand(req, n, cmd) # Delete the iota-emulation file created earlied for NMD. Mode change would have passed by now if it had to. cmd = "rm -f /data/iota-emulation" api.Trigger_AddNaplesCommand(req, n, cmd) resp = api.Trigger(req) for cmd in resp.commands: api.PrintCommandResults(cmd) if cmd.exit_code != 0: api.Logger.error("Agent system get failed : {}".format(cmd.node_name)) result = api.types.status.FAILURE out = None try: out = json.loads(cmd.stdout) except: api.Logger.error("Agent System get out failed {}".format(cmd.stdout)) return api.types.status.FAILURE if out["naples-mode"] != "NETWORK_MANAGED_OOB": api.Logger.error("Agent not in correct mode: {} {} ".format(cmd.node_name, out["naples-mode"])) return api.types.status.FAILURE api.Logger.info("Trying to re-enable ssh on naples nodes") return enable_ssh.Main(None)