~landscape/landscape-client/trunk

« back to all changes in this revision

Viewing changes to landscape/broker/tests/test_registration.py

Merge multiple-juju-unit-files [f=1325599] [r=ack,free.ekanayaka] [a=Chris Glass]
This branch creates a juju-info.d/ directory in the landscape-client data path, and reads all files matching *.json in this directory as a separate juju-info file.

It then reports juju-info lists to the server, either in the registration message or using a new message (to send a list of "juju info" instead of just one).

Show diffs side-by-side

added added

removed removed

Lines of Context:
511
511
 
512
512
    juju_contents = json.dumps({"environment-uuid": "DEAD-BEEF",
513
513
                                "unit-name": "service/0",
514
 
                                "api-addresses": "10.0.3.1:17070",
515
 
                                "private-address": "127.0.0.1"})
 
514
                                "api-addresses": "10.0.3.1:17070"})
516
515
 
517
516
    def test_juju_information_added_when_present(self):
518
517
        """
519
 
        When Juju information is found in $data_dir/juju-info.json,
 
518
        When Juju information is found in $data_dir/juju-info.d/*.json,
520
519
        key parts of it are sent in the registration message.
521
520
        """
522
521
        self.mstore.set_accepted_types(["register"])
529
528
                    "api-addresses": ["10.0.3.1:17070"],
530
529
                    "unit-name": "service/0"}
531
530
        self.assertEqual(expected, messages[0]["juju-info"])
 
531
        self.assertEqual(expected, messages[0]["juju-info-list"][0])
 
532
 
 
533
    def test_multiple_juju_information_added_when_present(self):
 
534
        """
 
535
        When Juju information is found in $data_dir/juju-info.json,
 
536
        key parts of it are sent in the registration message.
 
537
        """
 
538
        # Write a second file in the config directory
 
539
        contents = json.dumps({"environment-uuid": "DEAD-BEEF",
 
540
                               "unit-name": "service-2/0",
 
541
                               "api-addresses": "10.0.3.2:17070",
 
542
                               "private-address": "127.0.0.1"})
 
543
        self.makeFile(
 
544
            contents,
 
545
            dirname=self.config.juju_directory, suffix=".json")
 
546
 
 
547
        self.mstore.set_accepted_types(["register"])
 
548
        self.config.account_name = "account_name"
 
549
        self.reactor.fire("run")
 
550
        self.reactor.fire("pre-exchange")
 
551
 
 
552
        messages = self.mstore.get_pending_messages()
 
553
        juju_info = messages[0]["juju-info-list"]
 
554
        self.assertEqual(2, len(juju_info))
 
555
 
 
556
        expected1 = {"environment-uuid": "DEAD-BEEF",
 
557
                    "api-addresses": ["10.0.3.1:17070"],
 
558
                    "unit-name": "service/0"}
 
559
        self.assertIn(expected1, juju_info)
 
560
 
 
561
        expected2 = {"environment-uuid": "DEAD-BEEF",
 
562
                    "api-addresses": ["10.0.3.2:17070"],
 
563
                    "unit-name": "service-2/0",
 
564
                    "private-address": "127.0.0.1"}
 
565
        self.assertIn(expected2, juju_info)
532
566
 
533
567
 
534
568
class CloudRegistrationHandlerTest(RegistrationHandlerTestBase):