~hazmat/pyjuju/auto-magic-dependency-spec

« back to all changes in this revision

Viewing changes to ensemble/hooks/tests/test_invoker.py

Merging Jim's local-unit-name-in-one-line [r=niemeyer] [a=jimbaker] [f=712553]

This makes ENSEMBLE_UNIT_NAME be passed down into the
environment of hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
        yield super(TestInvoker, self).setUp()
110
110
 
111
111
        yield self._default_relations()
112
 
        self._manage_path()
 
112
        self._change_environment()
113
113
        self.socket_path = self.makeFile()
114
114
        self.ua = MockUnitAgent(self.client, self.socket_path)
115
115
 
118
118
        self.ua.stop()
119
119
        yield super(TestInvoker, self).tearDown()
120
120
 
121
 
    def _manage_path(self):
 
121
    def _change_environment(self):
122
122
        test_hook_path = os.path.join(
123
123
            os.path.abspath(
124
124
                os.path.dirname(__file__)).replace("/_trial_temp", ""),
125
125
            "hooks")
126
 
        self.change_environment(PATH=get_cli_environ_path(test_hook_path))
 
126
        self.change_environment(
 
127
            PATH=get_cli_environ_path(test_hook_path),
 
128
            ENSEMBLE_UNIT_NAME="mysql/1")
127
129
 
128
130
    @defer.inlineCallbacks
129
131
    def _default_relations(self):
131
133
            "wordpress", "client-server", "", "client")
132
134
        mysql_ep = RelationEndpoint(
133
135
            "mysql", "client-server", "", "server")
134
 
        self.wordpress_states = yield self.add_relation_service_unit_from_endpoints(
135
 
            wordpress_ep, mysql_ep)
 
136
        self.wordpress_states = \
 
137
            yield self.add_relation_service_unit_from_endpoints(
 
138
                wordpress_ep, mysql_ep)
136
139
        self.mysql_states = yield self.add_opposite_service_unit(
137
140
            self.wordpress_states)
138
141
        self.relation = self.mysql_states["unit_relation"]
168
171
        # this comes from updating the Invoker.environment
169
172
        self.assertEqual(env["FOO"], "bar")
170
173
 
 
174
        # and this comes from the unit agent passing through its environment
 
175
        self.assertTrue(env["PATH"])
 
176
        self.assertEqual(env["ENSEMBLE_UNIT_NAME"], "mysql/1")
 
177
 
171
178
    def test_missing_hook(self):
172
179
        self.save_logging()
173
180
 
191
198
        validate hook with success from exit
192
199
        """
193
200
        self.save_logging()
194
 
 
195
201
        exe = self.ua.get_invoker("database", "add", "mysql/1", self.relation)
196
202
        result = yield exe(self.get_test_hook("success-hook"))
197
203
        self.assertEqual(result, 0)
205
211
        """
206
212
        self.save_logging()
207
213
        self.reset_logging()
208
 
 
209
214
        exe = self.ua.get_invoker("database", "add", "mysql/1", self.relation)
210
215
        d = exe(self.get_test_hook("fail-hook"))
211
216
        result = yield self.assertFailure(d, errors.FormulaInvocationError)
232
237
        Validate the get hook can transmit values to the hook
233
238
        """
234
239
        hook_log = self.capture_logging("hook")
235
 
 
236
240
        exe = self.ua.get_invoker("database", "add", "mysql/1",
237
241
                                  self.relation,
238
242
                                  client_id="client_id")
259
263
        Validate the get hook can transmit values to the hook
260
264
        """
261
265
        hook_log = self.capture_logging("hook")
262
 
 
263
266
        exe = self.ua.get_invoker("database", "add", "mysql/1",
264
267
                                  self.relation,
265
268
                                  client_id="client_id")
301
304
    def test_logging(self):
302
305
        self.save_logging()
303
306
        self.reset_logging()
304
 
 
305
 
        #hook_log = self.capture_logging("hook")
306
 
 
307
307
        exe = self.ua.get_invoker("database", "add", "mysql/1", self.relation)
308
308
 
309
309
        # The echo hook will echo out the value
333
333
        """
334
334
        self.save_logging()
335
335
        self.reset_logging()
336
 
 
337
336
        exe = self.ua.get_invoker("database", "add", "mysql/1",
338
337
                                  self.relation,
339
338
                                  client_id="client_id")
362
361
        """
363
362
        self.save_logging()
364
363
        self.reset_logging()
365
 
 
366
364
        exe = self.ua.get_invoker("database", "add", "mysql/1",
367
365
                                  self.relation,
368
366
                                  client_id="client_id")
391
389
        """
392
390
        self.save_logging()
393
391
        self.reset_logging()
394
 
 
395
392
        exe = self.ua.get_invoker("database", "add", "mysql/1",
396
393
                                  self.relation,
397
394
                                  client_id="client_id")