Beispiel #1
0
    def test_profile_add(self):
        """Testing the profile add command execution"""

        sys.argv = [
            '/bin/rho', "profile", "add", "--name", "p1", "--hosts", "1.2.3.4",
            "--auth", "auth_1", "--vault", TMP_VAULT_PASS
        ]
        profiles = []
        with redirect_credentials([{
                'id': '1',
                'name': 'auth_1',
                'username': '******',
                'password': '******',
                'ssh_key_file': 'file'
        }]):
            with redirect_profiles(profiles):
                ProfileAddCommand().main()

        self.assertEqual(profiles, [{
            'name': 'p1',
            'hosts': ['1.2.3.4'],
            'ssh_port': '22',
            'auth': [{
                'id': '1',
                'name': 'auth_1'
            }]
        }])
Beispiel #2
0
    def test_a_profile_add(self):
        """Testing the profile add command execution"""

        sys.argv = [
            '/bin/rho', "profile", "add", "--name", "p1", "--hosts", "1.2.3.4",
            "--auth", "auth1", "--vault", TMP_VAULT_PASS
        ]
        ProfileAddCommand().main()
Beispiel #3
0
    def test_a_profile_add_existing(self):
        """Testing the profile add command execution"""

        with self.assertRaises(SystemExit):
            sys.argv = [
                '/bin/rho', "profile", "add", "--name", "p1", "--hosts",
                "1.2.3.4", "--auth", "auth1", "--vault", TMP_VAULT_PASS
            ]
            ProfileAddCommand().main()
Beispiel #4
0
    def test_profile_add_nonexist_auth(self):
        """Test the proile add command with an non-existent auth
        in order to catch error case
        """

        with self.assertRaises(SystemExit):
            sys.argv = ['/bin/rho', "profile", "add", "--name", "profile",
                        "hosts", "1.2.3.4", "--auth", "doesnotexist",
                        "--vault", TMP_VAULT_PASS]
            with redirect_credentials([]):
                ProfileAddCommand().main()
Beispiel #5
0
    def test_bad_range_options(self):
        """Test profile add command with an invalid host range"""

        # Should fail scanning range without a username:
        with self.assertRaises(SystemExit):
            sys.argv = [
                '/bin/rho', "profile", "add", "--name", "profilename", "hosts",
                "a:d:b:s", "--auths", "auth_1", "auth2", "--vault",
                TMP_VAULT_PASS
            ]
            ProfileAddCommand().main()
Beispiel #6
0
    def test_profile_add_hosts_file(self):
        """Test the profile command adding a profile with a file of hosts
        and an ordered list of auths
        """

        with self.assertRaises(SystemExit):
            sys.argv = [
                '/bin/rho', "profile", "add", "--name", "profilename", "hosts",
                TMP_HOSTS, "--auths", "auth_1", "auth2", "--vault",
                TMP_VAULT_PASS
            ]
            ProfileAddCommand().main()
Beispiel #7
0
    def test_profile_add_bad_port(self):
        """Testing the profile add command execution"""

        with self.assertRaises(SystemExit):
            sys.argv = ['/bin/rho', "profile", "add", "--name",
                        "p1", "--hosts", "1.2.3.4",
                        "--auth", "auth1", "--sshport", "abcd",
                        "--vault", TMP_VAULT_PASS]
            with redirect_profiles([{
                'name': 'p1',
                'hosts': ['1.2.3.4'],
                'ssh_port': '22',
                'auth': [{
                    'id': '1',
                    'name': 'auth_1'}]}]):
                ProfileAddCommand().main()
Beispiel #8
0
    def test_profile_add_hosts_list(self):
        """Test the profile command adding a profile with a list and
        range of hosts and an ordered list of auths
        """

        with self.assertRaises(SystemExit):
            sys.argv = ['/bin/rho', "profile", "add", "--name",
                        "profilename", "hosts",
                        "1.2.3.4", "1.2.3.[4:100]",
                        "--auths", "auth_1", "auth2",
                        "--vault", TMP_VAULT_PASS]
            with redirect_credentials([
                {'id': '1', 'name': 'auth_1',
                 'username': '******', 'password': '******',
                 'ssh_key_file': 'file'}]):
                ProfileAddCommand().main()