Exemplo n.º 1
0
    def test_update_targets_no_user(self):
        """
        test update_targets when no user defined
        """
        host = "127.0.0.1"
        opts = self.opts
        opts["tgt"] = host

        with patch("salt.utils.network.is_reachable_host",
                   MagicMock(return_value=False)):
            client = ssh.SSH(opts)
        assert opts["tgt"] == host
        client._update_targets()
        assert opts["tgt"] == host
Exemplo n.º 2
0
    def test_update_targets_dns(self):
        """
        test update_targets when host is dns
        """
        host = "localhost"
        user = "******"
        opts = self.opts
        opts["tgt"] = user + host

        with patch("salt.utils.network.is_reachable_host",
                   MagicMock(return_value=False)):
            client = ssh.SSH(opts)
        assert opts["tgt"] == user + host
        client._update_targets()
        assert opts["tgt"] == host
        assert client.targets[host]["user"] == user.split("@")[0]
Exemplo n.º 3
0
    def test_update_expand_target_dns(self):
        """
        test update_targets and expand_target when host is dns
        """
        host = "localhost"
        user = "******"
        opts = self.opts
        opts["tgt"] = user + host

        with patch("salt.utils.network.is_reachable_host",
                   MagicMock(return_value=False)):
            client = ssh.SSH(opts)
        assert opts["tgt"] == user + host
        with patch(
                "salt.roster.get_roster_file",
                MagicMock(return_value="/etc/salt/roster")), patch(
                    "salt.client.ssh.compile_template",
                    MagicMock(
                        return_value=salt.utils.yaml.safe_load(self.roster)),
                ):
            client._expand_target()
        client._update_targets()
        assert opts["tgt"] == host
        assert client.targets[host]["user"] == user.split("@")[0]