Skip to content

Commit

Permalink
fix parsing of env vars
Browse files Browse the repository at this point in the history
TIMEOUT and SLEEP were not working when set with ENV
Test case added to catch error in future
  • Loading branch information
viennaa committed Feb 15, 2021
1 parent 3f5bac2 commit 59c8e13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def parse_params(logger):
os.environ['ATLAS'] = options.atlas
if options.sleep:
os.environ['SLEEP'] = options.sleep
if not options.sleep:
if not options.sleep and 'SLEEP' not in os.environ:
logger.info('Defaulting sleep to 1800s')
os.environ['SLEEP'] = "1800"
if options.timeout:
os.environ['TIMEOUT'] = options.timeout
if not options.timeout:
if not options.timeout and 'TIMEOUT' not in os.environ:
logger.info('Defaulting timeout to 600s')
os.environ['TIMEOUT'] = "600"

Expand Down
18 changes: 18 additions & 0 deletions tests/TestLaunchInventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ def test_with_cli_and_env_params(self):
self.assertEqual(os.getenv('TIMEOUT'), '300', 'Timeout time was not set correctly')
self.assertEqual(logger.level, 30)

def test_env_params(self):
os.environ.clear()
os.environ['USER'] = 'testuser'
os.environ['PASSWORD'] = 'testpw31!'
os.environ['PORT'] = '1234'
os.environ['ATLAS'] = '/path/to/atlas.yaml'
os.environ['LOOPBACK'] = '0'
os.environ['SLEEP'] = '180'
os.environ['TIMEOUT'] = '60'
parse_params(logger)
self.assertEqual(os.getenv('USER'), 'testuser', 'The user was not set correctly!')
self.assertEqual(os.getenv('PASSWORD'), 'testpw31!', 'The password was not set correctly!')
self.assertEqual(os.getenv('PORT'), '1234', 'The port was not set correctly!')
self.assertEqual(os.getenv('ATLAS'), '/path/to/atlas.yaml', 'Atlas was not set correctly')
self.assertEqual(os.getenv('LOOPBACK'), '0', 'Loopback was not set correctly')
self.assertEqual(os.getenv('SLEEP'), '180', 'Sleep time was not set correctly')
self.assertEqual(os.getenv('TIMEOUT'), '60', 'Timeout time was not set correctly')

def test_with_bogus_options(self):
os.environ.clear()
sys.argv = ['prog', '-z', 'foo', '-x', 'bar', '-w', 'bar']
Expand Down

0 comments on commit 59c8e13

Please sign in to comment.