def test_vx_run_list_twice(self): # gymnastics for ansible stdin = sys.stdin argv = sys.argv sys.argv = [] sys.stdin = StringIO.StringIO('{"ANSIBLE_MODULE_ARGS": {}}') # start by doing some cleanup module = AnsibleModule(argument_spec=dict()) nclu.command_helper(module, 'abort') nclu.command_helper(module, 'del interface swp1') nclu.command_helper(module, 'commit') nclu.command_helper(module, 'abort') # run the test changed, output = nclu.run_nclu(module, ['add int swp1'], None, False, True, False, "atomically") self.assertEqual(changed, True) changed, output = nclu.run_nclu(module, ['add int swp1'], None, False, True, False, "atomically") self.assertEqual(changed, False) # gymnastics to fix ansible sys.stdin = stdin sys.argv = argv
def test_empty_run(self): module = FakeModule() changed, output = nclu.run_nclu(module, None, None, False, False, False, "") self.assertEqual(module.command_history, ['/usr/bin/net pending', '/usr/bin/net pending']) self.assertEqual(module.fail_code, {}) self.assertEqual(changed, False)
def test_commit_ignored(self): module = FakeModule() changed, output = nclu.run_nclu(module, None, None, True, False, False, "ignore me") self.assertEqual(module.command_history, [ '/usr/bin/net pending', '/usr/bin/net pending', "/usr/bin/net commit description 'ignore me'", '/usr/bin/net abort' ]) self.assertEqual(len(module.pending), 0) self.assertEqual(module.fail_code, {}) self.assertEqual(changed, False)
def test_command_list(self): module = FakeModule() changed, output = nclu.run_nclu(module, ['add int swp1', 'add int swp2'], None, False, False, False, "") self.assertEqual(module.command_history, [ '/usr/bin/net pending', '/usr/bin/net add int swp1', '/usr/bin/net add int swp2', '/usr/bin/net pending' ]) self.assertNotEqual(len(module.pending), 0) self.assertEqual(module.fail_code, {}) self.assertEqual(changed, True)
def test_command_template_commit(self): module = FakeModule() changed, output = nclu.run_nclu(module, None, " add int swp1\n add int swp2", True, False, False, "committed") self.assertEqual(module.command_history, [ '/usr/bin/net pending', '/usr/bin/net add int swp1', '/usr/bin/net add int swp2', '/usr/bin/net pending', "/usr/bin/net commit description 'committed'", '/usr/bin/net show commit last' ]) self.assertEqual(len(module.pending), 0) self.assertEqual(module.fail_code, {}) self.assertEqual(changed, True)
def test_command_atomic(self): module = FakeModule() changed, output = nclu.run_nclu(module, ['add int swp1', 'add int swp2'], None, False, True, False, "atomically") self.assertEqual(module.command_history, [ '/usr/bin/net abort', '/usr/bin/net pending', '/usr/bin/net add int swp1', '/usr/bin/net add int swp2', '/usr/bin/net pending', "/usr/bin/net commit description 'atomically'", '/usr/bin/net show commit last' ]) self.assertEqual(len(module.pending), 0) self.assertEqual(module.fail_code, {}) self.assertEqual(changed, True)
def test_command_abort_first(self): module = FakeModule() module.pending = "dirty" nclu.run_nclu(module, None, None, False, False, True, "") self.assertEqual(len(module.pending), 0)