~abentley/juju-ci-tools/client-from-config-4

« back to all changes in this revision

Viewing changes to tests/test_remote.py

  • Committer: Aaron Bentley
  • Date: 2016-03-18 14:47:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1324.
  • Revision ID: aaron.bentley@canonical.com-20160318144706-z7wy9c21m3psi6g5
Introduce set_model_name, update tests, check controller on bootstrap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    machines:
31
31
        "1":
32
32
            series: precise
33
 
    applications:
34
 
        a-application:
 
33
    services:
 
34
        a-service:
35
35
            units:
36
 
                a-application/0:
 
36
                a-service/0:
37
37
                    machine: "1"
38
38
                    public-address: 10.55.60.1
39
39
    """
42
42
    machines:
43
43
        "2":
44
44
            series: win2012hvr2
45
 
    applications:
46
 
        a-application:
 
45
    services:
 
46
        a-service:
47
47
            units:
48
 
                a-application/0:
 
48
                a-service/0:
49
49
                    machine: "2"
50
50
                    public-address: 10.55.60.2
51
51
    """
53
53
    def test_remote_from_unit(self):
54
54
        env = JujuData("an-env", {"type": "nonlocal"})
55
55
        client = EnvJujuClient(env, None, None)
56
 
        unit = "a-application/0"
 
56
        unit = "a-service/0"
57
57
        with patch.object(client, "get_status", autospec=True) as st:
58
58
            st.return_value = Status.from_text(self.precise_status_output)
59
59
            remote = remote_from_unit(client, unit)
60
60
        self.assertEqual(
61
61
            repr(remote),
62
 
            "<SSHRemote env='an-env' unit='a-application/0'>")
 
62
            "<SSHRemote env='an-env' unit='a-service/0'>")
63
63
        self.assertIs(False, remote.is_windows())
64
64
 
65
65
    def test_remote_from_unit_with_series(self):
66
66
        env = JujuData("an-env", {"type": "nonlocal"})
67
67
        client = EnvJujuClient(env, None, None)
68
 
        unit = "a-application/0"
 
68
        unit = "a-service/0"
69
69
        remote = remote_from_unit(client, unit, series="trusty")
70
70
        self.assertEqual(
71
71
            repr(remote),
72
 
            "<SSHRemote env='an-env' unit='a-application/0'>")
 
72
            "<SSHRemote env='an-env' unit='a-service/0'>")
73
73
        self.assertIs(False, remote.is_windows())
74
74
 
75
75
    def test_remote_from_unit_with_status(self):
76
76
        env = JujuData("an-env", {"type": "nonlocal"})
77
77
        client = EnvJujuClient(env, None, None)
78
 
        unit = "a-application/0"
 
78
        unit = "a-service/0"
79
79
        status = Status.from_text(self.win2012hvr2_status_output)
80
80
        remote = remote_from_unit(client, unit, status=status)
81
81
        self.assertEqual(
82
82
            repr(remote),
83
 
            "<WinRmRemote env='an-env' unit='a-application/0'"
84
 
            " addr='10.55.60.2'>")
 
83
            "<WinRmRemote env='an-env' unit='a-service/0' addr='10.55.60.2'>")
85
84
        self.assertIs(True, remote.is_windows())
86
85
 
87
86
    def test_remote_from_address(self):
102
101
    def test_run_with_unit(self):
103
102
        env = JujuData("an-env", {"type": "nonlocal"})
104
103
        client = EnvJujuClient(env, None, None)
105
 
        unit = "a-application/0"
 
104
        unit = "a-service/0"
106
105
        remote = remote_from_unit(client, unit, series="trusty")
107
106
        with patch.object(client, "get_juju_output") as mock_cmd:
108
107
            mock_cmd.return_value = "contents of /a/file"
114
113
    def test_run_with_unit_fallback(self):
115
114
        env = JujuData("an-env", {"type": "nonlocal"})
116
115
        client = EnvJujuClient(env, None, None)
117
 
        unit = "a-application/0"
 
116
        unit = "a-service/0"
118
117
        with patch.object(client, "get_status") as st:
119
118
            st.return_value = Status.from_text(self.precise_status_output)
120
119
            remote = remote_from_unit(client, unit)
138
137
        ])
139
138
        self.assertRegexpMatches(
140
139
            self.log_stream.getvalue(),
141
 
            "(?m)^WARNING juju ssh to 'a-application/0' failed, .*")
 
140
            "(?m)^WARNING juju ssh to 'a-service/0' failed, .*")
142
141
 
143
142
    def test_run_with_address(self):
144
143
        remote = remote_from_address("10.55.60.1")
173
172
    def test_cat_on_windows(self):
174
173
        env = JujuData("an-env", {"type": "nonlocal"})
175
174
        client = EnvJujuClient(env, None, None)
176
 
        unit = "a-application/0"
 
175
        unit = "a-service/0"
177
176
        with patch.object(client, "get_status", autospec=True) as st:
178
177
            st.return_value = Status.from_text(self.win2012hvr2_status_output)
179
178
            response = winrm.Response(("contents of /a/file", "",  0))
205
204
    def test_copy_on_windows(self):
206
205
        env = JujuData("an-env", {"type": "nonlocal"})
207
206
        client = EnvJujuClient(env, None, None)
208
 
        unit = "a-application/0"
 
207
        unit = "a-service/0"
209
208
        dest = "/local/path"
210
209
        with patch.object(client, "get_status", autospec=True) as st:
211
210
            st.return_value = Status.from_text(self.win2012hvr2_status_output)
244
243
    def test_run_cmd(self):
245
244
        env = JujuData("an-env", {"type": "nonlocal"})
246
245
        client = EnvJujuClient(env, None, None)
247
 
        unit = "a-application/0"
 
246
        unit = "a-service/0"
248
247
        with patch.object(client, "get_status", autospec=True) as st:
249
248
            st.return_value = Status.from_text(self.win2012hvr2_status_output)
250
249
            response = winrm.Response(("some out", "some err",  0))