From b82001fcd4a308e0f2a2d60893076287bb6a26d2 Mon Sep 17 00:00:00 2001 From: Matthew Muscat Date: Sun, 11 Jan 2015 12:57:26 +1100 Subject: [PATCH 1/3] Update hosts file creation for consistency and better readability Update hosts file format to consistent format, including when adding and removing multiple aliases for a single ip eg: 127.0.0.1 alias1 alias2, which is comprised of... IP Address + TAB TAB + alias1 + space + alias2 + (space + aliasx)... Current behaviour is to use double tab spacing between all elements, but rm_hosts process results in a single tab being used. --- salt/modules/hosts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/modules/hosts.py b/salt/modules/hosts.py index f0466c6ce3..16aa2684bb 100644 --- a/salt/modules/hosts.py +++ b/salt/modules/hosts.py @@ -181,11 +181,11 @@ def rm_host(ip, alias): continue comps = tmpline.split() if comps[0] == ip: - newline = '{0}\t'.format(comps[0]) + newline = '{0}\t\t'.format(comps[0]) for existing in comps[1:]: if existing == alias: continue - newline += '\t{0}'.format(existing) + newline += ' {0}'.format(existing) if newline.strip() == ip: # No aliases exist for the line, make it empty lines[ind] = '' @@ -237,7 +237,7 @@ def _write_hosts(hosts): else: line = '{0}\t\t{1}'.format( ip, - '\t\t'.join(aliases) + ' '.join(aliases) ) lines.append(line) From f44d67471dec2d61c8b724dffdbb26fe3cf8754a Mon Sep 17 00:00:00 2001 From: Matthew Muscat Date: Sun, 18 Jan 2015 00:33:00 +1100 Subject: [PATCH 2/3] Update hosts module test Update test case to account for formatting changes in b82001fcd4a308e0f2a2d60893076287bb6a26d2 --- tests/integration/modules/hosts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/modules/hosts.py b/tests/integration/modules/hosts.py index 602dae0fcf..ff1d0debe5 100644 --- a/tests/integration/modules/hosts.py +++ b/tests/integration/modules/hosts.py @@ -210,8 +210,8 @@ class HostsModuleTest(integration.ModuleCase): lines = salt.utils.fopen(HFN, 'r').read().splitlines() self.assertEqual(lines, [ '192.168.1.3\t\thost3.fqdn.com', - '192.168.1.1\t\thost1.fqdn.com\t\thost1\t\thost1-reorder', - '192.168.1.2\t\thost2.fqdn.com\t\thost2\t\toldhost2\t\thost2-reorder', + '192.168.1.1\t\thost1.fqdn.com host1 host1-reorder', + '192.168.1.2\t\thost2.fqdn.com host2 oldhost2 host2-reorder', ]) From ed1e87eaf79292e2a84b599b99ed982c3444f8ed Mon Sep 17 00:00:00 2001 From: Dmitry Kuzmenko Date: Mon, 19 Jan 2015 16:30:30 +0300 Subject: [PATCH 3/3] Don't run deeds in SetUp, use enter and recur. Presence test update: 1. Don't run deeds in test SetUp method. 2. Don't use benter. Use enter and recur instead. 3. Removed useless returns from actors (erroneously added before). --- salt/daemons/flo/core.py | 1 - salt/daemons/test/plan/actors.py | 2 - salt/daemons/test/test_presence.py | 280 ++++++++++++++++++++++++----- 3 files changed, 235 insertions(+), 48 deletions(-) diff --git a/salt/daemons/flo/core.py b/salt/daemons/flo/core.py index bae78a458f..f22d88771f 100644 --- a/salt/daemons/flo/core.py +++ b/salt/daemons/flo/core.py @@ -708,7 +708,6 @@ class SaltRaetManorLaneSetup(ioflo.base.deeding.Deed): for index in range(self.opts.value['worker_threads']): worker_seed.append('worker{0}'.format(index + 1)) self.workers.value = itertools.cycle(worker_seed) - return True class SaltRaetLaneStackCloser(ioflo.base.deeding.Deed): # pylint: disable=W0232 diff --git a/salt/daemons/test/plan/actors.py b/salt/daemons/test/plan/actors.py index c1a9be9d9d..9875050f2b 100644 --- a/salt/daemons/test/plan/actors.py +++ b/salt/daemons/test/plan/actors.py @@ -96,7 +96,6 @@ class PresenterTestOptsSetup(ioflo.base.deeding.Deed): open_mode=True, auto_accept=True, ) - return True def serviceStacks(stacks, duration=1.0): @@ -162,7 +161,6 @@ class PresenterTestSetup(ioflo.base.deeding.Deed): msg = {'route': route} stack.transmit(msg, stack.nameRemotes[ryn].uid) serviceStacks([stack, self.lane_stack.value]) - return True class PresenterTestCleanup(ioflo.base.deeding.Deed): diff --git a/salt/daemons/test/test_presence.py b/salt/daemons/test/test_presence.py index 7d30dee8b4..c65af9ac31 100644 --- a/salt/daemons/test/test_presence.py +++ b/salt/daemons/test/test_presence.py @@ -41,43 +41,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): Call super if override so House Framer and Frame are setup correctly """ super(PresenterTestCase, self).setUp() - self.addBenterDeed("PresenterTestOptsSetup") - self.addBenterDeed("SaltRaetManorLaneSetup") - self.addBenterDeed("PresenterTestSetup") - - self.act = self.addEnterDeed("SaltRaetPresenter") - self.assertIn(self.act, self.frame.enacts) - self.assertEqual(self.act.actor, "SaltRaetPresenter") - - self.resolve() # resolve House, Framer, Frame, Acts, Actors - self.frame.checkEnter() - self.assertDictEqual(self.act.actor.Ioinits, - {'opts': '.salt.opts', - 'presence_req': '.salt.presence.event_req', - 'lane_stack': '.salt.lane.manor.stack', - 'alloweds': '.salt.var.presence.alloweds', - 'aliveds': '.salt.var.presence.aliveds', - 'reapeds': '.salt.var.presence.reapeds', - 'availables': '.salt.var.presence.availables'}) - - self.assertTrue(hasattr(self.act.actor, 'opts')) - self.assertTrue(hasattr(self.act.actor, 'presence_req')) - self.assertTrue(hasattr(self.act.actor, 'lane_stack')) - self.assertTrue(hasattr(self.act.actor, 'alloweds')) - self.assertTrue(hasattr(self.act.actor, 'aliveds')) - self.assertTrue(hasattr(self.act.actor, 'reapeds')) - self.assertTrue(hasattr(self.act.actor, 'availables')) - self.assertIsInstance(self.act.actor.lane_stack.value, LaneStack) def tearDown(self): """ Call super if override so House Framer and Frame are torn down correctly """ - self.act.actor.lane_stack.value.server.close() - testStack = self.store.fetch('.salt.test.lane.stack').value - testStack.server.close() - super(PresenterTestCase, self).tearDown() @@ -98,12 +67,70 @@ class PresenterTestCase(testing.FrameIofloTestCase): availables.value.add(name) + def testContextSetup(self): + """ + Test the context setup procedure used in all the consequence tests works as expected + This test intended to avoid some checks in other tests + """ + console.terse("{0}\n".format(self.testContextSetup.__doc__)) + + act = self.addEnterDeed("PresenterTestOptsSetup") + self.assertIn(act, self.frame.enacts) + self.assertEqual(act.actor, "PresenterTestOptsSetup") + act = self.addEnterDeed("SaltRaetManorLaneSetup") + self.assertIn(act, self.frame.enacts) + self.assertEqual(act.actor, "SaltRaetManorLaneSetup") + act = self.addEnterDeed("PresenterTestSetup") + self.assertIn(act, self.frame.enacts) + self.assertEqual(act.actor, "PresenterTestSetup") + + act = self.addRecurDeed("SaltRaetPresenter") + self.assertIn(act, self.frame.reacts) + self.assertEqual(act.actor, "SaltRaetPresenter") + + self.resolve() # resolve House, Framer, Frame, Acts, Actors + + self.frame.enter() + self.assertDictEqual(act.actor.Ioinits, + {'opts': '.salt.opts', + 'presence_req': '.salt.presence.event_req', + 'lane_stack': '.salt.lane.manor.stack', + 'alloweds': '.salt.var.presence.alloweds', + 'aliveds': '.salt.var.presence.aliveds', + 'reapeds': '.salt.var.presence.reapeds', + 'availables': '.salt.var.presence.availables'}) + + self.assertTrue(hasattr(act.actor, 'opts')) + self.assertTrue(hasattr(act.actor, 'presence_req')) + self.assertTrue(hasattr(act.actor, 'lane_stack')) + self.assertTrue(hasattr(act.actor, 'alloweds')) + self.assertTrue(hasattr(act.actor, 'aliveds')) + self.assertTrue(hasattr(act.actor, 'reapeds')) + self.assertTrue(hasattr(act.actor, 'availables')) + self.assertIsInstance(act.actor.lane_stack.value, LaneStack) + self.frame.recur() + + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + + def testPresenceAvailable(self): """ Test Presenter 'available' request (A1, B*) """ console.terse("{0}\n".format(self.testPresenceAvailable.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add available minions self.addAvailable('alpha') @@ -136,7 +163,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): # Test # process 5 requests at once - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -152,6 +179,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'present': {'alpha': '1.1.1.1', 'beta': '1.2.3.4'}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceJoined(self): """ @@ -159,6 +192,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceJoined.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add joined minions # NOTE: for now alloweds are threaded as joineds @@ -174,7 +215,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): presenceReq.append(msg) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -189,6 +230,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'joined': {'alpha': '1.1.1.1', 'beta': '1.2.3.4'}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceAllowed(self): """ @@ -196,6 +243,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceAllowed.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add allowed minions self.addPresenceInfo('alloweds', 'alpha', '1.1.1.1', '1234') @@ -210,7 +265,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): presenceReq.append(msg) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -225,6 +280,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'allowed': {'alpha': '1.1.1.1', 'beta': '1.2.3.4'}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceAlived(self): """ @@ -232,6 +293,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceAlived.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add alived minions self.addPresenceInfo('aliveds', 'alpha', '1.1.1.1', '1234') @@ -246,7 +315,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): presenceReq.append(msg) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -261,6 +330,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'alived': {'alpha': '1.1.1.1', 'beta': '1.2.3.4'}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceReaped(self): """ @@ -268,6 +343,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceReaped.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add reaped minions self.addPresenceInfo('reapeds', 'alpha', '1.1.1.1', '1234') @@ -282,7 +365,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): presenceReq.append(msg) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -297,6 +380,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'reaped': {'alpha': '1.1.1.1', 'beta': '1.2.3.4'}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceNoRequest(self): """ @@ -304,8 +393,16 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceNoRequest.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check testStack = self.store.fetch('.salt.test.lane.stack').value @@ -313,6 +410,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): testStack.serviceAll() self.assertEqual(len(testStack.rxMsgs), 0) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceUnknownSrc(self): """ @@ -320,6 +423,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceUnknownSrc.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add presence request testStack = self.store.fetch('.salt.test.lane.stack').value @@ -332,13 +443,19 @@ class PresenterTestCase(testing.FrameIofloTestCase): presenceReq.append(msg) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) testStack.serviceAll() self.assertEqual(len(testStack.rxMsgs), 0) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceAvailableNoMinions(self): """ @@ -346,6 +463,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceAvailableNoMinions.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add presence request testStack = self.store.fetch('.salt.test.lane.stack').value @@ -356,7 +481,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'state': 'available'}}) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -370,6 +495,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'tag': tag, 'data': {'present': {}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceAvailableOneMinion(self): """ @@ -377,6 +508,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceAvailableOneMinion.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add available minions self.addAvailable('alpha') @@ -390,7 +529,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'state': 'available'}}) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -404,6 +543,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'tag': tag, 'data': {'present': {'alpha': '1.1.1.1'}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceAvailableSomeIpUnknown(self): """ @@ -411,6 +556,14 @@ class PresenterTestCase(testing.FrameIofloTestCase): """ console.terse("{0}\n".format(self.testPresenceAvailableSomeIpUnknown.__doc__)) + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() + # Prepare # add available minions self.addAvailable('alpha') @@ -427,7 +580,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'data': {'state': 'available'}}) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -443,12 +596,26 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'beta': None, 'gamma': None}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceAllowedNoMinions(self): """ Test Presenter 'allowed' request with no minions in the state (D4) """ - console.terse("{0}\n".format(self.testPresenceAllowed.__doc__)) + console.terse("{0}\n".format(self.testPresenceAllowedNoMinions.__doc__)) + + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() # Prepare # add presence request @@ -461,7 +628,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): presenceReq.append(msg) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -475,12 +642,26 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'tag': tag, 'data': {'allowed': {}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def testPresenceAllowedOneMinion(self): """ Test Presenter 'allowed' request with one minion in the state (D5) """ - console.terse("{0}\n".format(self.testPresenceAllowed.__doc__)) + console.terse("{0}\n".format(self.testPresenceAllowedOneMinion.__doc__)) + + # Bootstrap + self.addEnterDeed("PresenterTestOptsSetup") + self.addEnterDeed("SaltRaetManorLaneSetup") + self.addEnterDeed("PresenterTestSetup") + act = self.addRecurDeed("SaltRaetPresenter") + self.resolve() # resolve House, Framer, Frame, Acts, Actors + self.frame.enter() # Prepare # add allowed minions @@ -495,7 +676,7 @@ class PresenterTestCase(testing.FrameIofloTestCase): presenceReq.append(msg) # Test - self.frame.enter() # run in frame + self.frame.recur() # run in frame # Check self.assertEqual(len(testStack.rxMsgs), 0) @@ -509,6 +690,12 @@ class PresenterTestCase(testing.FrameIofloTestCase): 'tag': tag, 'data': {'allowed': {'alpha': '1.1.1.1'}}}) + # Close active stacks servers + act.actor.lane_stack.value.server.close() + testStack = self.store.fetch('.salt.test.lane.stack') + if testStack: + testStack.value.server.close() + def runOne(test): ''' @@ -523,6 +710,7 @@ def runSome(): """ Unittest runner """ tests = [] names = [ + 'testContextSetup', 'testPresenceAvailable', 'testPresenceJoined', 'testPresenceAllowed', @@ -533,6 +721,8 @@ def runSome(): 'testPresenceAvailableNoMinions', 'testPresenceAvailableOneMinion', 'testPresenceAvailableSomeIpUnknown', + 'testPresenceAllowedNoMinions', + 'testPresenceAllowedOneMinion', ] tests.extend(map(PresenterTestCase, names)) suite = unittest.TestSuite(tests)