Skip to content

Commit

Permalink
fix: VSC keeps trying to setup public VLAN
Browse files Browse the repository at this point in the history
for setting public vlans we were retrying on last nic, added a check
for if old_vlan==new_vlan.
fixed minor issue on ls-interface displaying ip instead of mac.
fixed pexpect sripts to avoid waiting for exit since child.close is
already dealing with that.
added warning to validate_env for when grace period not expired.

Change-Id: Iad030637cfe9dbffe9c293bf8b931554055ab1fd
  • Loading branch information
grafuls committed Mar 6, 2020
1 parent 89a3e56 commit 8df97f4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 44 deletions.
2 changes: 1 addition & 1 deletion bin/quads-cli
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions quads/tools/juniper_convert_port_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 2 additions & 8 deletions quads/tools/juniper_set_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions quads/tools/move_and_rebuild_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions quads/tools/validate_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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
Expand Down
33 changes: 18 additions & 15 deletions quads/tools/verify_switchconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand Down

0 comments on commit 8df97f4

Please sign in to comment.