Test multiple nxos versions at once (#25595)

* Extend tests to have multiple device representations

* Move filepath munging to nxos_module

* Device needs to be kwarg so we can leave it off

* Update other nxos tests

* Update tests that fell through
This commit is contained in:
Nathaniel Case
2017-06-27 12:45:36 -04:00
committed by GitHub
parent 79b2897462
commit 3d6d428bbc
30 changed files with 86 additions and 72 deletions

View File

@@ -36,8 +36,10 @@ fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
def load_fixture(module_name, name, device=''):
path = os.path.join(fixture_path, module_name, device, name)
if not os.path.exists(path):
path = os.path.join(fixture_path, module_name, name)
if path in fixture_data:
return fixture_data[path]
@@ -64,9 +66,27 @@ class AnsibleFailJson(Exception):
class TestNxosModule(unittest.TestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
def execute_module_devices(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
module_name = self.module.__name__.rsplit('.', 1)[1]
local_fixture_path = os.path.join(fixture_path, module_name)
self.load_fixtures(commands)
models = []
for path in os.listdir(local_fixture_path):
path = os.path.join(local_fixture_path, path)
if os.path.isdir(path):
models.append(os.path.basename(path))
if not models:
models = ['']
retvals = {}
for model in models:
retvals[model] = self.execute_module(failed, changed, commands, sort, device=model)
return retvals
def execute_module(self, failed=False, changed=False, commands=None, sort=True, device=''):
self.load_fixtures(commands, device=device)
if failed:
result = self.failed()
@@ -110,5 +130,5 @@ class TestNxosModule(unittest.TestCase):
self.assertEqual(result['changed'], changed, result)
return result
def load_fixtures(self, commands=None):
def load_fixtures(self, commands=None, device=''):
pass