Skip to content

Commit 0fafc1f

Browse files
authored
Merge pull request #102 from CiscoDevNet/vb-edits
Update verify.py
2 parents 4957ee5 + 1809ee4 commit 0fafc1f

2 files changed

Lines changed: 45 additions & 19 deletions

File tree

verify/backend/spark.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env python
2-
"""Verify the Cisco Spark APIs are accessible and responding.
2+
"""Verify the Cisco Webex APIs are accessible and responding.
33
44
Verify that user's provide SPARK_ACCESS_TOKEN is valid and that calls to the
5-
Cisco Spark APIs complete successfully.
5+
Cisco Webex (formerly Spark) APIs complete successfully. Uses SPARK_
6+
for variable names; the product name is Cisco Webex.
67
78
8-
Copyright (c) 2018 Cisco and/or its affiliates.
9+
Copyright (c) 2018-21 Cisco and/or its affiliates.
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -48,10 +49,10 @@
4849

4950

5051
def verify() -> bool:
51-
"""Verify access to the Cisco Spark APIs."""
52-
print("==> Verifying access to the Cisco Spark APIs")
52+
"""Verify access to the Cisco Webex APIs."""
53+
print("==> Verifying access to the Cisco Webex APIs")
5354

54-
# Check to ensure the user has provided their Spark Access Token
55+
# Check to ensure the user has provided their Webex Access Token
5556
if not env_user.SPARK_ACCESS_TOKEN:
5657
print(
5758
"\nFAILED: You must provide your SPARK_ACCESS_TOKEN in the "
@@ -63,35 +64,35 @@ def verify() -> bool:
6364
access_token=env_user.SPARK_ACCESS_TOKEN
6465
)
6566

66-
# Verify the Cisco Spark APIs are accessible and responding
67+
# Verify the Cisco Webex APIs are accessible and responding
6768
try:
6869
me = spark.people.me()
6970
except ciscosparkapi.SparkApiError as e:
7071
print(
71-
"\nFAILED: The API call to Cisco Spark returned the following "
72+
"\nFAILED: The API call to Cisco Webex returned the following "
7273
"error:\n{}\n".format(e)
7374
)
7475
return False
7576

7677
else:
7778
print(
78-
"\nYou are connected to Cisco Spark as: {}\n".format(me.emails[0])
79+
"\nYou are connected to Cisco Webex (formerly Cisco Spark) as: {}\n".format(me.emails[0])
7980
)
8081

81-
# Check to ensure the user has provided a Spark Room ID
82+
# Check to ensure the user has provided a Webex Room ID
8283
if not env_user.SPARK_ROOM_ID:
8384
print(
8485
"\nFAILED: You must provide the SPARK_ROOM_ID of the room you "
8586
"want to work with in the env_user.py file.\n"
8687
)
8788
return False
8889

89-
# Verify the Spark Room exists and is accessible via the access token
90+
# Verify the Webex Room exists and is accessible via the access token
9091
try:
9192
room = spark.rooms.get(env_user.SPARK_ROOM_ID)
9293
except ciscosparkapi.SparkApiError as e:
9394
print(
94-
"\nFAILED: There was an error accessing the Spark Room using the "
95+
"\nFAILED: There was an error accessing the Webex Room using the "
9596
"SPARK_ROOM_ID you provided; error details:\n{}\n".format(e)
9697
)
9798
return False

verify/verify.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
environments are accessible and responding to API calls.
77
88
9-
Copyright (c) 2018 Cisco and/or its affiliates.
9+
Copyright (c) 2018-21 Cisco and/or its affiliates.
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -71,20 +71,45 @@
7171
sys.exit(1)
7272

7373

74+
fail_bit = 0
75+
76+
77+
if env_lab.ENVIRONMENT_IN_USE == "sandbox" or env_lab.ENVIRONMENT_IN_USE == "express" or env_lab.ENVIRONMENT_IN_USE =="custom":
78+
print(f"env_lab.py - ENVIRONMENT_IN_USE: {env_lab.ENVIRONMENT_IN_USE}")
79+
else:
80+
print("\nImproper value inputted. go to env_lab.py and select either sandbox, express, or custom.")
81+
print(f"ERROR: env_lab.py - Invalid ENVIRONMENT_IN_USE: {env_lab.ENVIRONMENT_IN_USE}")
82+
fail_bit = 1
83+
84+
print(f"env_user.py - SPARK_ACCESS_TOKEN: {env_user.SPARK_ACCESS_TOKEN}")
85+
print(f"env_user.py - SPARK_ROOM_ID: {env_user.SPARK_ROOM_ID}")
86+
print(f"env_user.py - MERAKI_API_KEY: {env_user.MERAKI_API_KEY}\n")
87+
7488
# Verify backend lab environments
7589
backend = os.path.abspath(os.path.join(here, "backend"))
7690
verified = []
7791
for python_file in glob(os.path.join(backend, "*.py")):
7892
name = os.path.splitext(os.path.basename(python_file))[0]
7993
spec = spec_from_file_location(name, python_file)
8094
module = module_from_spec(spec)
81-
spec.loader.exec_module(module)
82-
verified.append(module.verify())
83-
84-
if all(verified):
85-
print("\nAll lab backend systems are responding. You're good to go!")
95+
try:
96+
spec.loader.exec_module(module)
97+
verified.append(module.verify())
98+
except ModuleNotFoundError:
99+
print("\nFAILED: Error importing module. You need to install lab requirements. \n\tEnter Command: pip install -r requirements.txt")
100+
fail_bit = 1
101+
break
102+
except AttributeError:
103+
print("\nFAILED: Error due to invalid ENVIRONMENT_IN_USE input in the env_lab.py file. \n\tCheck to see if the environment requires VPN access.")
104+
fail_bit = 1
105+
break
106+
107+
if fail_bit == 1:
108+
print("\nCorrect Errors and rerun.\n")
109+
elif all(verified):
110+
print("\nAll lab backend systems are responding. You're good to go!\n")
86111
else:
87112
print(
88113
"\nSome of the backend systems didn't respond or reported errors; "
89-
"please check the above output for details."
114+
"please check the above output for details.\n"
90115
)

0 commit comments

Comments
 (0)