def test_commands_add(self): """ Tests adding commands to an existing list. """ ctx = sm.ServiceContext(INFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] self.assertEqual(len(svc.commands), 8) svc.commands.append( sm.Command("foo", "bar", commitOnSuccess=False, description="Description of foo bar")) svc.commands.append( sm.Command("bar", "baz", commitOnSuccess=True, description="Description of bar baz")) ctx.commit(OUTFILENAME) ctx = sm.ServiceContext(OUTFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] if not "foo" in [command.name for command in svc.commands]: raise ValueError("Failed to alter commands.") if not "bar" in [command.name for command in svc.commands]: raise ValueError("Failed to alter commands.") for command in svc.commands: if command.name == "foo": self.assertEqual(command.command, "bar") self.assertEqual(command.description, "Description of foo bar") self.assertFalse(command.commitOnSuccess) if command.name == "bar": self.assertEqual(command.command, "baz") self.assertEqual(command.description, "Description of bar baz") self.assertTrue(command.commitOnSuccess) self.assertEqual(len(svc.commands), 10)
def test_commands_replace(self): """ Tests completely replacing the commands list. """ ctx = sm.ServiceContext(INFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] svc.commands = [ sm.Command("foo", "bar", commitOnSuccess=False), sm.Command("bar", "baz", commitOnSuccess=True), ] ctx.commit(OUTFILENAME) ctx = sm.ServiceContext(OUTFILENAME) svc = filter(lambda x: x.description == "Zope server", ctx.services)[0] if not "foo" in [command.name for command in svc.commands]: raise ValueError("Failed to alter commands.") if not "bar" in [command.name for command in svc.commands]: raise ValueError("Failed to alter commands.") for command in svc.commands: if command.name == "foo": self.assertEqual(command.command, "bar") self.assertFalse(command.commitOnSuccess) if command.name == "bar": self.assertEqual(command.command, "baz") self.assertTrue(command.commitOnSuccess) self.assertEqual(len(svc.commands), 2)
def commandDictList(commandDict): commandList = [] for k, v in commandDict.iteritems(): commandList.append( sm.Command(k, command=v["Command"], commitOnSuccess=v["CommitOnSuccess"])) return commandList
application="application", portnumber=9012, protocol="TCP", addressConfig=sm.AddressConfig(3456, "UDP"))) # Remove the "help" command. svc.commands = filter(lambda x: x.name != "help", svc.commands) # Alter the "upgrade" command. upgrade = filter(lambda x: x.name == "upgrade", svc.commands)[0] upgrade.name = "upgrade renamed" upgrade.command = "upgrade command" upgrade.commitOnSuccess = False # Add a new command. svc.commands.append(sm.Command("new command", "new command", False)) # Remove the "zenjobs" volume. svc.volumes = filter(lambda x: x.resourcePath != "zenjobs", svc.volumes) # Alter the ".ssh" volume. ssh = filter(lambda x: x.resourcePath == ".ssh", svc.volumes)[0] ssh.owner = "ssh owner" ssh.permission = "0000" ssh.resourcePath = "ssh resource path" ssh.containerPath = "ssh/container/path" # Create a new volume. svc.volumes.append( sm.Volume(owner="new volume owner", permission="1111",