Example #1
0
    def test_get_exec_command(self):
        l = ExecCommandList()
        assert_a = lambda a: self.assertEqual(l.get_type_item(a),
                                              ExecCommand('a b c', None, ExecPolicy.RESTART))
        assert_b = lambda b: self.assertEqual(l.get_type_item(b),
                                              ExecCommand(['a', 'b', 'c'], None, ExecPolicy.RESTART))
        assert_c = lambda c: self.assertEqual(l.get_type_item(c),
                                              ExecCommand('a b c', 'user', ExecPolicy.RESTART))
        assert_d = lambda d: self.assertEqual(l.get_type_item(d),
                                              ExecCommand(['a', 'b', 'c'], 'user', ExecPolicy.RESTART))
        assert_e = lambda e: self.assertEqual(l.get_type_item(e),
                                              ExecCommand('a b c', 'user', ExecPolicy.INITIAL))
        assert_f = lambda f: self.assertEqual(l.get_type_item(f),
                                              ExecCommand(['a', 'b', 'c'], 'user', ExecPolicy.INITIAL))

        assert_a('a b c')
        assert_a(('a b c', ))
        assert_a(['a b c', None])
        assert_a(lazy_once(lambda: 'a b c'))
        assert_b((['a', 'b', 'c'],))
        assert_b([['a', 'b', 'c'], None])
        assert_c(('a b c', 'user'))
        assert_c([lazy_once(lambda: 'a b c'), lazy_once(lambda: 'user')])
        assert_d((['a', 'b', 'c'], 'user'))
        assert_d([lazy_once(lambda: ['a', 'b', 'c']), lazy_once(lambda: 'user')])
        assert_e(('a b c', 'user', ExecPolicy.INITIAL))
        assert_e([lazy_once(lambda: 'a b c'), lazy_once(lambda: 'user'), ExecPolicy.INITIAL])
        assert_f((['a', 'b', 'c'], 'user', ExecPolicy.INITIAL))
        assert_f([lazy_once(lambda: ['a', 'b', 'c']), lazy_once(lambda: 'user'), ExecPolicy.INITIAL])
        assert_f({'cmd': ['a', 'b', 'c'], 'user': '******', 'policy': ExecPolicy.INITIAL})
Example #2
0
    def test_get_exec_command(self):
        assert_a = lambda a: self.assertEqual(get_exec_command(a),
                                              ExecCommand('a b c', None, EXEC_POLICY_RESTART))
        assert_b = lambda b: self.assertEqual(get_exec_command(b),
                                              ExecCommand(['a', 'b', 'c'], None, EXEC_POLICY_RESTART))
        assert_c = lambda c: self.assertEqual(get_exec_command(c),
                                              ExecCommand('a b c', 'user', EXEC_POLICY_RESTART))
        assert_d = lambda d: self.assertEqual(get_exec_command(d),
                                              ExecCommand(['a', 'b', 'c'], 'user', EXEC_POLICY_RESTART))
        assert_e = lambda e: self.assertEqual(get_exec_command(e),
                                              ExecCommand('a b c', 'user', EXEC_POLICY_INITIAL))
        assert_f = lambda f: self.assertEqual(get_exec_command(f),
                                              ExecCommand(['a', 'b', 'c'], 'user', EXEC_POLICY_INITIAL))

        assert_a('a b c')
        assert_a(('a b c', ))
        assert_a(['a b c', None])
        assert_a(lazy_once(lambda: 'a b c'))
        assert_b((['a', 'b', 'c'],))
        assert_b([['a', 'b', 'c'], None])
        assert_c(('a b c', 'user'))
        assert_c([lazy_once(lambda: 'a b c'), lazy_once(lambda: 'user')])
        assert_d((['a', 'b', 'c'], 'user'))
        assert_d([lazy_once(lambda: ['a', 'b', 'c']), lazy_once(lambda: 'user')])
        assert_e(('a b c', 'user', EXEC_POLICY_INITIAL))
        assert_e([lazy_once(lambda: 'a b c'), lazy_once(lambda: 'user'), EXEC_POLICY_INITIAL])
        assert_f((['a', 'b', 'c'], 'user', EXEC_POLICY_INITIAL))
        assert_f([lazy_once(lambda: ['a', 'b', 'c']), lazy_once(lambda: 'user'), EXEC_POLICY_INITIAL])
Example #3
0
    def test_get_port_binding(self):
        assert_a = lambda a: self.assertEqual(get_port_binding(a), PortBinding('1234', None, None))
        assert_b = lambda b: self.assertEqual(get_port_binding(b), PortBinding(1234, 1234, None))
        assert_c = lambda c: self.assertEqual(get_port_binding(c), PortBinding(1234, 1234, '0.0.0.0'))

        assert_a('1234')
        assert_a(('1234', ))
        assert_a(['1234', None])
        assert_b((1234, lazy_once(lambda: 1234)))
        assert_c((1234, 1234, '0.0.0.0'))
        assert_c((1234, [1234, '0.0.0.0']))
Example #4
0
def expand_env_lazy(loader, node):
    """
    Substitutes a variable read from a YAML node with the value stored in Fabric's ``env`` dictionary. Creates an
    object for late resolution.

    :param loader: YAML loader.
    :type loader: yaml.loader.SafeLoader
    :param node: Document node.
    :type node: ScalarNode
    :return: Corresponding value stored in the ``env`` dictionary.
    :rtype: any
    """
    val = loader.construct_scalar(node)
    return lazy_once(env_get, val)
Example #5
0
    def test_get_exec_command(self):
        assert_a = lambda a: self.assertEqual(
            get_exec_command(a), ExecCommand('a b c', None, EXEC_POLICY_RESTART
                                             ))
        assert_b = lambda b: self.assertEqual(
            get_exec_command(b),
            ExecCommand(['a', 'b', 'c'], None, EXEC_POLICY_RESTART))
        assert_c = lambda c: self.assertEqual(
            get_exec_command(c),
            ExecCommand('a b c', 'user', EXEC_POLICY_RESTART))
        assert_d = lambda d: self.assertEqual(
            get_exec_command(d),
            ExecCommand(['a', 'b', 'c'], 'user', EXEC_POLICY_RESTART))
        assert_e = lambda e: self.assertEqual(
            get_exec_command(e),
            ExecCommand('a b c', 'user', EXEC_POLICY_INITIAL))
        assert_f = lambda f: self.assertEqual(
            get_exec_command(f),
            ExecCommand(['a', 'b', 'c'], 'user', EXEC_POLICY_INITIAL))

        assert_a('a b c')
        assert_a(('a b c', ))
        assert_a(['a b c', None])
        assert_a(lazy_once(lambda: 'a b c'))
        assert_b((['a', 'b', 'c'], ))
        assert_b([['a', 'b', 'c'], None])
        assert_c(('a b c', 'user'))
        assert_c([lazy_once(lambda: 'a b c'), lazy_once(lambda: 'user')])
        assert_d((['a', 'b', 'c'], 'user'))
        assert_d(
            [lazy_once(lambda: ['a', 'b', 'c']),
             lazy_once(lambda: 'user')])
        assert_e(('a b c', 'user', EXEC_POLICY_INITIAL))
        assert_e([
            lazy_once(lambda: 'a b c'),
            lazy_once(lambda: 'user'), EXEC_POLICY_INITIAL
        ])
        assert_f((['a', 'b', 'c'], 'user', EXEC_POLICY_INITIAL))
        assert_f([
            lazy_once(lambda: ['a', 'b', 'c']),
            lazy_once(lambda: 'user'), EXEC_POLICY_INITIAL
        ])
Example #6
0
    def test_get_port_binding(self):
        l = PortBindingList()
        assert_a = lambda a: self.assertEqual(l.get_type_item(a), PortBinding('1234'))
        assert_b = lambda b: self.assertEqual(l.get_type_item(b), PortBinding(1234, 1234))
        assert_c = lambda c: self.assertEqual(l.get_type_item(c), PortBinding(1234, 1234, '0.0.0.0'))
        assert_d = lambda d: self.assertEqual(l.get_type_item(d), PortBinding(1234, 1234, '0.0.0.0', True))

        assert_a('1234')
        assert_a(('1234', ))
        assert_a(['1234', None])
        assert_a({'exposed_port': '1234'})
        assert_b((1234, lazy_once(lambda: 1234)))
        assert_c((1234, 1234, '0.0.0.0'))
        assert_c((1234, [1234, '0.0.0.0']))
        assert_d((1234, 1234, '0.0.0.0', True))
        assert_d(dict(exposed_port=1234, host_port=1234, interface='0.0.0.0', ipv6=True))
        assert_d((1234, [1234, '0.0.0.0', True]))
Example #7
0
 def test_get_list(self):
     self.assertEqual(get_list(()), [])
     self.assertEqual(get_list(None), [])
     self.assertEqual(get_list(lazy_once(lambda: 'test')), ['test'])
     self.assertEqual(get_list('test'), ['test'])