mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user