setup-kubectl/test/validate-kubectl.py

31 lines
999 B
Python
Raw Normal View History

Refactoring Action for use with AKS Atlanta (#37) * Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Grabbed the upstream integration tests and brought them here. Removed bash script. Added validateKubectl.py to /test folder for integration tests. * Ran npm run build * Ran npm run build * Updated on section for integration-tests.yml * Removing ruby commands from integration tests yaml. * Fixing discrepancies in integration test yaml. * Fixing discrepancies in integration test yaml. * Default to ubuntu-latest * renamed python script according to workflow. * renamed python script according to workflow. * Fixing path parameters. * Updated tsconfig.json * Testing for int test failure. * Validated that int tests work. * Added new workflows. * Testing release (#10) * Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src. * Grabbed the upstream integration tests and brought them here. Removed bash script. Added validateKubectl.py to /test folder for integration tests. * Ran npm run build * Ran npm run build * Updated on section for integration-tests.yml * Removing ruby commands from integration tests yaml. * Fixing discrepancies in integration test yaml. * Fixing discrepancies in integration test yaml. * Default to ubuntu-latest * renamed python script according to workflow. * renamed python script according to workflow. * Fixing path parameters. * Updated tsconfig.json * Testing for int test failure. * Validated that int tests work. * Added new workflows. Co-authored-by: Tommy Barnes <thbarnes@microsoft.com> * made changes reflected in comments Co-authored-by: Tommy Barnes <thbarnes@microsoft.com>
2022-01-05 17:19:30 +01:00
import os, sys, json, requests, time
version_to_check = sys.argv[1]
version_info = None
PASSED = False
try:
print('kubectl version --client -o json')
version_info = json.load(os.popen('kubectl version --client -o json'))
except Exception as ex:
sys.exit('kubectl not installed')
try:
if version_to_check == 'latest':
response = None
time_to_sleep = 2
for _ in range(10):
response = requests.get('https://storage.googleapis.com/kubernetes-release/release/stable.txt')
if response.status_code == 200:
break
print('Failed to obtain latest version info, retrying.')
time.sleep(time_to_sleep)
time_to_sleep *= 2
version_to_check = response.content.decode('utf-8')
PASSED = True if version_info['clientVersion']['gitVersion'] == version_to_check else False
except:
pass
if not PASSED:
sys.exit('Setting up of '+version_to_check+' kubectl failed')
print('Test passed')