diff --git a/bin/quads-cli b/bin/quads-cli index cfc2a4090..97811be64 100755 --- a/bin/quads-cli +++ b/bin/quads-cli @@ -114,7 +114,7 @@ def main(_args): for interface in sorted(result, key=lambda k: k['name']): message = \ f"interface: {interface['name']}, " \ - f"mac address: {interface['ip_address']}, " \ + f"mac address: {interface['mac_address']}, " \ f"switch IP: {interface['ip_address']}, " \ f"port: {interface['switch_port']}" logger.info(message) diff --git a/quads/tools/juniper_convert_port_public.py b/quads/tools/juniper_convert_port_public.py index 407b59461..25afeca38 100755 --- a/quads/tools/juniper_convert_port_public.py +++ b/quads/tools/juniper_convert_port_public.py @@ -40,22 +40,15 @@ def juniper_convert_port_public(ip_address, switch_port, old_vlan, new_pub_vlan) switch_port, str(new_pub_vlan))) child.expect("#") - if old_vlan: + if old_vlan and old_vlan != new_pub_vlan: logger.debug("delete vlans vlan%s interface %s" % (str(old_vlan), switch_port)) child.sendline("delete vlans vlan%s interface %s" % (str(old_vlan), switch_port)) child.expect("#") logger.debug("commit") child.sendline("commit") - child.waitnoecho(timeout=120) - child.expect("#") - - logger.debug("exit") - child.sendline("exit") - child.expect(">") + child.expect("commit complete", timeout=120) - logger.debug("exit") - child.sendline("exit") child.close() except pexpect.exceptions.TIMEOUT: diff --git a/quads/tools/juniper_set_port.py b/quads/tools/juniper_set_port.py index 6398f1518..cecad2c34 100755 --- a/quads/tools/juniper_set_port.py +++ b/quads/tools/juniper_set_port.py @@ -41,16 +41,10 @@ def juniper_set_port(ip_address, switch_port, old_vlan, new_vlan): logger.debug("commit") child.sendline("commit") - child.waitnoecho(timeout=120) - child.expect("#") - - logger.debug("exit") - child.sendline("exit") - child.expect(">") + child.expect("commit complete", timeout=120) - logger.debug("exit") - child.sendline("exit") child.close() + except pexpect.exceptions.TIMEOUT: logger.error("Timeout trying to change settings on switch %s" % ip_address) return False diff --git a/quads/tools/move_and_rebuild_hosts.py b/quads/tools/move_and_rebuild_hosts.py index 458fa77f9..5e06db954 100755 --- a/quads/tools/move_and_rebuild_hosts.py +++ b/quads/tools/move_and_rebuild_hosts.py @@ -30,6 +30,7 @@ def switch_config(host, old_cloud, new_cloud): ssh_helper = None interfaces = sorted(_host_obj.interfaces, key=lambda k: k['name']) for i, interface in enumerate(interfaces): + last_nic = i == len(_host_obj.interfaces) - 1 if not switch_ip: switch_ip = interface.ip_address ssh_helper = SSHHelper(switch_ip, conf["junos_username"]) @@ -43,18 +44,18 @@ def switch_config(host, old_cloud, new_cloud): if old_vlan_out: old_vlan = old_vlan_out[0].split(";")[0].split()[1][7:] if not old_vlan: - logger.warning( - "Warning: Could not determine the previous VLAN for %s on %s, switch %s, switchport %s" - % (host, interface.name, interface.ip_address, interface.switch_port) - ) + if not _new_cloud_obj.vlan and not last_nic: + logger.warning( + "Warning: Could not determine the previous VLAN for %s on %s, switch %s, switchport %s" + % (host, interface.name, interface.ip_address, interface.switch_port) + ) old_vlan = get_vlan(_old_cloud_obj, i) new_vlan = get_vlan(_new_cloud_obj, i) - if _new_cloud_obj.vlan and i == len(_host_obj.interfaces) - 1: - logger.info("Setting last interface to public vlan %s." % new_vlan) - + if _new_cloud_obj.vlan and last_nic: if int(old_vlan) != int(_new_cloud_obj.vlan.vlan_id): + logger.info("Setting last interface to public vlan %s." % new_vlan) success = juniper_convert_port_public( interface.ip_address, interface.switch_port, @@ -67,7 +68,6 @@ def switch_config(host, old_cloud, new_cloud): logger.error("There was something wrong updating switch for %s:%s" % (host, interface.name)) return False else: - if int(old_vlan) != int(new_vlan): success = juniper_set_port( interface.ip_address, diff --git a/quads/tools/validate_env.py b/quads/tools/validate_env.py index 38b910688..40de13b6b 100755 --- a/quads/tools/validate_env.py +++ b/quads/tools/validate_env.py @@ -64,8 +64,12 @@ def env_allocation_time_exceeded(self): now = datetime.now() schedule = Schedule.objects(cloud=self.cloud, start__lt=now, end__gt=now).first() time_delta = now - schedule.start - if time_delta.seconds//60 > conf["validation_grace_period"]: + if time_delta.seconds // 60 > conf["validation_grace_period"]: return True + logger.warning( + "You're still within the configurable validation grace period. Skipping validation for %s." + % self.cloud.name + ) return False def post_system_test(self): @@ -134,7 +138,6 @@ def post_network_test(self): host_list = " ".join([host.name for host in self.hosts]) if type(ssh_helper.run_cmd("fping -u %s" % host_list)) != list: - return False for i, interface in enumerate(INTERFACES.keys()): @@ -177,7 +180,7 @@ def validate_env(self): if not self.post_system_test(): failed = True - if not self.post_network_test(): + if not failed and not self.post_network_test(): failed = True # TODO: gather ansible-cmdb facts diff --git a/quads/tools/verify_switchconf.py b/quads/tools/verify_switchconf.py index cea71d86a..1c711844f 100755 --- a/quads/tools/verify_switchconf.py +++ b/quads/tools/verify_switchconf.py @@ -46,19 +46,21 @@ def verify(_cloud_name, change=False): vlan_member_out = ssh_helper.run_cmd("show configuration vlans | display set | match %s.0" % interface.switch_port) vlan_member = vlan_member_out[0].split()[2][4:].strip(",") except IndexError: - logger.warning( - "Could not determine the previous VLAN member for %s on %s, switch %s, switchport %s" - % (_host["name"], interface.name, interface.ip_address, interface.switch_port) - ) + if not _cloud_obj.vlan and not last_nic: + logger.warning( + "Could not determine the previous VLAN member for %s on %s, switch %s, switchport %s" + % (_host["name"], interface.name, interface.ip_address, interface.switch_port) + ) vlan_member = None ssh_helper.disconnect() if not old_vlan: - logger.warning( - "Could not determine the previous VLAN for %s on %s, switch %s, switchport %s" - % (_host["name"], interface.name, interface.ip_address, interface.switch_port) - ) + if not _cloud_obj.vlan and not last_nic: + logger.warning( + "Could not determine the previous VLAN for %s on %s, switch %s, switchport %s" + % (_host["name"], interface.name, interface.ip_address, interface.switch_port) + ) old_vlan = get_vlan(_cloud_obj, i, last_nic) if int(old_vlan) != int(vlan): @@ -68,17 +70,18 @@ def verify(_cloud_name, change=False): vlan = _cloud_obj.vlan.vlan_id if not vlan_member or int(vlan_member) != int(vlan): - logger.warning( - "interface %s appears to be a member of VLAN %s, should be %s", - interface.switch_port, - vlan_member, - vlan - ) + if not _cloud_obj.vlan and not last_nic: + logger.warning( + "interface %s appears to be a member of VLAN %s, should be %s", + interface.switch_port, + vlan_member, + vlan + ) if change: logger.info('=== INFO: change requested') - if _cloud_obj.vlan and last_nic: + if _cloud_obj.vlan and _cloud_obj.vlan != old_vlan and last_nic: logger.info("Setting last interface to public vlan %s." % _cloud_obj.vlan.vlan_id) success = juniper_convert_port_public(