328
328
self.mstore.set_accepted_types(["distribution-info", "computer-info"])
329
329
self.assertMessages(list(self.mstore.get_pending_messages()), [])
331
def test_extra_meta_data(self):
331
def test_annotations(self):
333
L{ComputerInfo} sends extra meta data the meta-data.d directory
333
L{ComputerInfo} sends extra meta data the annotations.d directory
336
Each file name is used as a key in the extra-meta-data dict and
336
Each file name is used as a key in the annotations dict and
337
337
the file's contents are used as values.
339
339
This allows, for example, the landscape-client charm to send
340
340
information about the juju environment to the landscape server.
342
meta_data_dir = self.monitor.config.meta_data_path
343
os.mkdir(meta_data_dir)
344
create_file(os.path.join(meta_data_dir, "juju-env-uuid"), "uuid1")
345
create_file(os.path.join(meta_data_dir, "juju-unit-name"), "unit/0")
342
annotations_dir = self.monitor.config.annotations_path
343
os.mkdir(annotations_dir)
344
create_file(os.path.join(annotations_dir, "annotation1"), "value1")
345
create_file(os.path.join(annotations_dir, "annotation2"), "value2")
346
346
self.mstore.set_accepted_types(["computer-info"])
348
348
plugin = ComputerInfo()
350
350
plugin.exchange()
351
351
messages = self.mstore.get_pending_messages()
352
352
self.assertEqual(1, len(messages))
353
meta_data = messages[0]["extra-meta-data"]
353
meta_data = messages[0]["annotations"]
354
354
self.assertEqual(2, len(meta_data))
355
self.assertEqual("uuid1", meta_data["juju-env-uuid"])
356
self.assertEqual("unit/0", meta_data["juju-unit-name"])
355
self.assertEqual("value1", meta_data["annotation1"])
356
self.assertEqual("value2", meta_data["annotation2"])
358
def test_extra_meta_data_no_directory(self):
360
L{ComputerInfo} doesn't include the extra-meta-data key if there
361
is no meta-data.d directory.
363
meta_data_dir = self.monitor.config.meta_data_path
358
def test_annotations_no_directory(self):
360
L{ComputerInfo} doesn't include the annotations key if there
361
is no annotations.d directory.
363
meta_data_dir = self.monitor.config.annotations_path
364
364
self.assertFalse(os.path.exists(meta_data_dir))
365
365
self.mstore.set_accepted_types(["computer-info"])
369
369
plugin.exchange()
370
370
messages = self.mstore.get_pending_messages()
371
371
self.assertEqual(1, len(messages))
372
self.assertNotIn("extra-meta-data", messages[0])
372
self.assertNotIn("annotations", messages[0])
374
374
def test_extra_meta_data_empty_directory(self):
376
L{ComputerInfo} doesn't include the extra-meta-data key if the
377
meta-data.d directory doesn't contain any files.
376
L{ComputerInfo} doesn't include the annotations key if the
377
annotations.d directory doesn't contain any files.
379
meta_data_dir = self.monitor.config.meta_data_path
379
meta_data_dir = self.monitor.config.annotations_path
380
380
os.mkdir(meta_data_dir)
381
381
self.mstore.set_accepted_types(["computer-info"])
385
385
plugin.exchange()
386
386
messages = self.mstore.get_pending_messages()
387
387
self.assertEqual(1, len(messages))
388
self.assertNotIn("extra-meta-data", messages[0])
388
self.assertNotIn("annotations", messages[0])