Exemplo n.º 1
0
    def testInstanceAugmentationProxiedMaster(self):
        import ploy.tests.dummy_proxy_plugin
        import ploy.plain

        self.configfile.fill(
            [
                "[plain-instance:foo]",
                "somevalue = ham",
                "[dummy-master:master]",
                "instance = foo",
                "[dummy-instance:bar]",
                "dummy_value = egg",
            ]
        )
        ctrl = Controller(configpath=self.directory)
        ctrl.configfile = self.configfile.path
        ctrl.plugins = {"dummy": ploy.tests.dummy_proxy_plugin.plugin, "plain": ploy.plain.plugin}
        # trigger augmentation of all instances
        instances = dict(ctrl.instances)
        # check the proxied value, which is only accessible through the instance config
        assert "somevalue" in instances["master"].config
        assert instances["master"].config["somevalue"] == "ham"
        # we check that the main config is updated for the remaining values,
        # not only the individual instance configs
        assert "dummy_value" in ctrl.config["dummy-instance"]["bar"]
        assert ctrl.config["dummy-instance"]["bar"]["dummy_value"] == "egg massaged"
        assert "dummy_augmented" in ctrl.config["dummy-instance"]["bar"]
        assert ctrl.config["dummy-instance"]["bar"]["dummy_augmented"] == "augmented massaged"
Exemplo n.º 2
0
 def testInstanceAugmentationProxiedMaster(self):
     import ploy.tests.dummy_proxy_plugin
     import ploy.plain
     self.configfile.fill([
         '[plain-instance:foo]',
         'somevalue = ham',
         '[dummy-master:master]',
         'instance = foo',
         '[dummy-instance:bar]',
         'dummy_value = egg'])
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     ctrl.plugins = {
         'dummy': ploy.tests.dummy_proxy_plugin.plugin,
         'plain': ploy.plain.plugin}
     # trigger augmentation of all instances
     instances = dict(ctrl.instances)
     # check the proxied value, which is only accessible through the instance config
     assert 'somevalue' in instances['master'].config
     assert instances['master'].config['somevalue'] == 'ham'
     # we check that the main config is updated for the remaining values,
     # not only the individual instance configs
     assert 'dummy_value' in ctrl.config['dummy-instance']['bar']
     assert ctrl.config['dummy-instance']['bar']['dummy_value'] == 'egg massaged'
     assert 'dummy_augmented' in ctrl.config['dummy-instance']['bar']
     assert ctrl.config['dummy-instance']['bar']['dummy_augmented'] == 'augmented massaged'
Exemplo n.º 3
0
def ctrl(ployconf, tempdir, sshconfig):
    import ploy.plain
    ctrl = Controller(tempdir.directory)
    ctrl.plugins = {
        'plain': ploy.plain.plugin}
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 4
0
def ctrl(ployconf, tempdir):
    from ploy import Controller
    import ploy.tests.dummy_plugin
    ctrl = Controller(tempdir.directory)
    ctrl.plugins = {'dummy': ploy.tests.dummy_plugin.plugin}
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 5
0
 def testMissingConfig(self):
     os.remove(self.configfile.path)
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     with patch("ploy.log") as LogMock:
         with pytest.raises(SystemExit):
             ctrl.config
         LogMock.error.assert_called_with("Config '%s' doesn't exist." % ctrl.configfile)
Exemplo n.º 6
0
 def testMissingConfig(self):
     os.remove(self.configfile.path)
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     with patch('ploy.log') as LogMock:
         with pytest.raises(SystemExit):
             ctrl.config
         LogMock.error.assert_called_with("Config '%s' doesn't exist." % ctrl.configfile)
Exemplo n.º 7
0
def ctrl(ployconf, tempdir):
    from ploy import Controller
    import ploy.tests.dummy_plugin
    ctrl = Controller(tempdir.directory)
    ctrl.plugins = {
        'dummy': ploy.tests.dummy_plugin.plugin}
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 8
0
    def testInstanceAugmentation(self):
        import ploy.tests.dummy_plugin

        self.configfile.fill(["[dummy-instance:foo]"])
        ctrl = Controller(configpath=self.directory)
        ctrl.configfile = self.configfile.path
        ctrl.plugins = {"dummy": ploy.tests.dummy_plugin.plugin}
        assert "dummy_augmented" in ctrl.instances["foo"].config
        assert ctrl.instances["foo"].config["dummy_augmented"] == "augmented massaged"
Exemplo n.º 9
0
def ctrl(ployconf):
    import ploy_fabric
    import ploy.tests.dummy_plugin
    ctrl = Controller(ployconf.directory)
    ctrl.plugins = {
        'dummy': ploy.tests.dummy_plugin.plugin,
        'fabric': ploy_fabric.plugin}
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 10
0
 def testConflictingPluginCommandName(self):
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     ctrl.plugins = dict(dummy=dict(
         get_commands=lambda x: [
             ('ssh', None)]))
     with patch('ploy.log') as LogMock:
         with pytest.raises(SystemExit):
             ctrl([])
     LogMock.error.assert_called_with("Command name '%s' of '%s' conflicts with existing command name.", 'ssh', 'dummy')
Exemplo n.º 11
0
 def testConflictingPluginCommandName(self):
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     ctrl.plugins = dict(dummy=dict(get_commands=lambda x: [("ssh", None)]))
     with patch("ploy.log") as LogMock:
         with pytest.raises(SystemExit):
             ctrl([])
     LogMock.error.assert_called_with(
         "Command name '%s' of '%s' conflicts with existing command name.", "ssh", "dummy"
     )
Exemplo n.º 12
0
 def testInstanceAugmentation(self):
     import ploy.tests.dummy_plugin
     self.configfile.fill([
         '[dummy-instance:foo]'])
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     ctrl.plugins = {
         'dummy': ploy.tests.dummy_plugin.plugin}
     assert 'dummy_augmented' in ctrl.instances['foo'].config
     assert ctrl.instances['foo'].config['dummy_augmented'] == 'augmented massaged'
Exemplo n.º 13
0
def ctrl(ployconf):
    from ploy import Controller
    import ploy.plain
    import ploy.tests.dummy_proxy_plugin
    ployconf.fill([''])
    ctrl = Controller(configpath=ployconf.directory)
    ctrl.plugins = {
        'dummy': ploy.tests.dummy_proxy_plugin.plugin,
        'plain': ploy.plain.plugin}
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 14
0
 def testInvalidInstanceName(self):
     import ploy.tests.dummy_plugin
     self.configfile.fill([
         '[dummy-instance:fo o]'])
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     ctrl.plugins = {'dummy': ploy.tests.dummy_plugin.plugin}
     with patch('ploy.common.log') as LogMock:
         with pytest.raises(SystemExit):
             ctrl(['./bin/ploy', 'ssh', 'bar'])
     LogMock.error.assert_called_with("Invalid instance name 'fo o'. An instance name may only contain letters, numbers, dashes and underscores.")
Exemplo n.º 15
0
def ctrl(ployconf):
    from ploy import Controller
    import ploy.plain
    import ploy.tests.dummy_proxy_plugin
    ployconf.fill([''])
    ctrl = Controller(configpath=ployconf.directory)
    ctrl.plugins = {
        'dummy': ploy.tests.dummy_proxy_plugin.plugin,
        'plain': ploy.plain.plugin
    }
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 16
0
    def testConflictingInstanceShortName(self):
        import ploy.tests.dummy_plugin
        import ploy.plain

        self.configfile.fill(["[dummy-instance:foo]", "[plain-instance:foo]"])
        ctrl = Controller(configpath=self.directory)
        ctrl.configfile = self.configfile.path
        ctrl.plugins = {"dummy": ploy.tests.dummy_plugin.plugin, "plain": ploy.plain.plugin}
        with patch("sys.stderr") as StdErrMock:
            with pytest.raises(SystemExit):
                ctrl(["./bin/ploy", "ssh", "bar"])
        output = "".join(x[0][0] for x in StdErrMock.write.call_args_list)
        assert "(choose from 'default-foo', 'plain-foo')" in output
Exemplo n.º 17
0
    def testInvalidInstanceName(self):
        import ploy.tests.dummy_plugin

        self.configfile.fill(["[dummy-instance:fo o]"])
        ctrl = Controller(configpath=self.directory)
        ctrl.configfile = self.configfile.path
        ctrl.plugins = {"dummy": ploy.tests.dummy_plugin.plugin}
        with patch("ploy.common.log") as LogMock:
            with pytest.raises(SystemExit):
                ctrl(["./bin/ploy", "ssh", "bar"])
        LogMock.error.assert_called_with(
            "Invalid instance name 'fo o'. An instance name may only contain letters, numbers, dashes and underscores."
        )
Exemplo n.º 18
0
def test_instance_massagers():
    directory = tempfile.mkdtemp()
    ctrl = Controller(directory)
    ctrl.configfile = os.path.join(directory, 'ploy.conf')
    _write_config(directory, '\n'.join([
        '[instance:bar]',
        'master = default',
        'startup_script = startup.sh',
        '[ec2-instance:ham]']))
    massagers = ctrl.instances['bar'].config.massagers
    assert massagers != {}
    assert ctrl.instances['bar'].config == {
        'startup_script': {'path': os.path.join(directory, 'startup.sh')},
        'master': 'default'}
Exemplo n.º 19
0
def ctrl(ployconf, tempdir):
    from ploy import Controller
    import bsdploy
    import ploy_ezjail
    import ploy_ansible
    ployconf.fill([
        '[ez-master:jailhost]'])
    ctrl = Controller(configpath=ployconf.directory)
    ctrl.plugins = {
        'bsdploy': bsdploy.plugin,
        'ezjail': ploy_ezjail.plugin,
        'ansible': ploy_ansible.plugin}
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 20
0
def ctrl(ployconf, tempdir):
    from ploy import Controller
    import bsdploy
    import ploy_ezjail
    import ploy_ansible
    ployconf.fill(['[ez-master:jailhost]'])
    ctrl = Controller(configpath=ployconf.directory)
    ctrl.plugins = {
        'bsdploy': bsdploy.plugin,
        'ezjail': ploy_ezjail.plugin,
        'ansible': ploy_ansible.plugin
    }
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 21
0
def ctrl(ployconf, ezjail_name):
    from ploy import Controller
    import ploy_ezjail
    lines = [
        '[ez-master:warden]',
        '[ez-instance:foo]',
        'ip = 10.0.0.1']
    if ezjail_name is not 'foo':
        lines.append('ezjail-name = %s' % ezjail_name)
    ployconf.fill(lines)
    ctrl = Controller(configpath=ployconf.directory)
    ctrl.configfile = ployconf.path
    ctrl.plugins = {'ezjail': ploy_ezjail.plugin}
    return ctrl
Exemplo n.º 22
0
 def testConflictingInstanceShortName(self):
     import ploy.tests.dummy_plugin
     import ploy.plain
     self.configfile.fill([
         '[dummy-instance:foo]',
         '[plain-instance:foo]'])
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     ctrl.plugins = {
         'dummy': ploy.tests.dummy_plugin.plugin,
         'plain': ploy.plain.plugin}
     with patch('sys.stderr') as StdErrMock:
         with pytest.raises(SystemExit):
             ctrl(['./bin/ploy', 'ssh', 'bar'])
     output = "".join(x[0][0] for x in StdErrMock.write.call_args_list)
     assert "(choose from 'default-foo', 'plain-foo')" in output
Exemplo n.º 23
0
def ctrl(ployconf, tempdir):
    from ploy import Controller
    import bsdploy
    import ploy.plain
    import ploy_ezjail
    import ploy_fabric
    ployconf.fill(
        ['[ez-master:jailhost]', '[instance:foo]', 'master = jailhost'])
    ctrl = Controller(configpath=ployconf.directory)
    ctrl.plugins = {
        'bsdploy': bsdploy.plugin,
        'ezjail': ploy_ezjail.plugin,
        'fabric': ploy_fabric.plugin,
        'plain': ploy.plain.plugin
    }
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 24
0
def ctrl(ployconf):
    from ploy import Controller
    import ploy_ansible
    import ploy.tests.dummy_plugin
    ployconf.fill([
        '[dummy-instance:foo]',
        'host = foo'])
    ctrl = Controller(ployconf.directory)
    ctrl.configfile = ployconf.path
    ctrl.plugins = {
        'dummy': ploy.tests.dummy_plugin.plugin,
        'ansible': ploy_ansible.plugin}
    if hasattr(ploy_ansible, 'display'):
        ploy_ansible.display._deprecations.clear()
        ploy_ansible.display._warns.clear()
        ploy_ansible.display._errors.clear()
    return ctrl
Exemplo n.º 25
0
def test_instance_massagers():
    directory = tempfile.mkdtemp()
    ctrl = Controller(directory)
    ctrl.configfile = os.path.join(directory, 'ploy.conf')
    _write_config(
        directory, '\n'.join([
            '[instance:bar]', 'master = default',
            'startup_script = startup.sh', '[ec2-instance:ham]'
        ]))
    massagers = ctrl.instances['bar'].config.massagers
    assert massagers != {}
    assert ctrl.instances['bar'].config == {
        'startup_script': {
            'path': os.path.join(directory, 'startup.sh')
        },
        'master': 'default'
    }
Exemplo n.º 26
0
def ctrl(ployconf, tempdir):
    from ploy import Controller
    import bsdploy
    import ploy.plain
    import ploy_ezjail
    import ploy_fabric
    ployconf.fill([
        '[ez-master:jailhost]',
        '[instance:foo]',
        'master = jailhost'])
    ctrl = Controller(configpath=ployconf.directory)
    ctrl.plugins = {
        'bsdploy': bsdploy.plugin,
        'ezjail': ploy_ezjail.plugin,
        'fabric': ploy_fabric.plugin,
        'plain': ploy.plain.plugin}
    ctrl.configfile = ployconf.path
    return ctrl
Exemplo n.º 27
0
 def ctrl(self, ployconf):
     from ploy import Controller
     import ploy.tests.dummy_plugin
     ployconf.fill([
         '[dummy-master:warden]',
         '[dummy-master:master]',
         '[dummy-master:another]',
         '[dummy-instance:foo]',
         'master = warden',
         '[dummy-instance:bar]',
         'master = master',
         '[dummy-instance:ham]',
         'master = warden master',
         '[dummy-instance:egg]'])
     ctrl = Controller(configpath=ployconf.directory)
     ctrl.plugins = {
         'dummy': ploy.tests.dummy_plugin.plugin}
     ctrl.configfile = ployconf.path
     yield ctrl
Exemplo n.º 28
0
 def ctrl(self, ployconf):
     from ploy import Controller
     import ploy.tests.dummy_plugin
     ployconf.fill([
         '[dummy-master:warden]',
         '[dummy-master:master]',
         '[dummy-master:another]',
         '[dummy-instance:foo]',
         'master = warden',
         '[dummy-instance:bar]',
         'master = master',
         '[dummy-instance:ham]',
         'master = warden master',
         '[dummy-instance:egg]'])
     ctrl = Controller(configpath=ployconf.directory)
     ctrl.plugins = {
         'dummy': ploy.tests.dummy_plugin.plugin}
     ctrl.configfile = ployconf.path
     yield ctrl
Exemplo n.º 29
0
 def testKnownHostsWithNoConfigErrors(self):
     os.remove(self.configfile.path)
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     with pytest.raises(SystemExit):
         ctrl.known_hosts
Exemplo n.º 30
0
 def testKnownHosts(self):
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     assert ctrl.known_hosts == os.path.join(self.directory, "known_hosts")
Exemplo n.º 31
0
 def testKnownHostsWithNoConfigErrors(self):
     os.remove(self.configfile.path)
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     with pytest.raises(SystemExit):
         ctrl.known_hosts
Exemplo n.º 32
0
 def testKnownHosts(self):
     ctrl = Controller(configpath=self.directory)
     ctrl.configfile = self.configfile.path
     assert ctrl.known_hosts == os.path.join(self.directory, 'known_hosts')