コード例 #1
0
ファイル: test_bundleParser.py プロジェクト: jawmin/Cloud_WS
    def test_getrelations(self):
        # no relation section
        bundle = BundleParser(self.norelation)
        if bundle.getrelations():
            self.fail()

        # complete relation
        bundle = BundleParser(self.correct)
        if not bundle.getrelations():
            self.fail()
コード例 #2
0
ファイル: test_bundleParser.py プロジェクト: jawmin/Cloud_WS
    def test_setservicename(self):
        # unknown service change requested
        bundle = BundleParser(self.correct)
        self.assertRaises(BundleError, bundle.setservicename, "fake", "even_more")

        # test name correctly changed
        bundle.setservicename("mysql", "database")
        # check service exists
        self.assertIsNotNone(bundle.getservice("database"))
        # check relation changed and : not affected
        # check :
        found = [True for relation in bundle.getrelations() if "database:db" in relation]
        self.assertTrue(found)
        # check without :
        found = [True for relation in bundle.getrelations() if "database" in relation]
        self.assertTrue(found)
コード例 #3
0
ファイル: core.py プロジェクト: jawmin/Cloud_WS
    def deploybundle(self, bundle_data):
        self.logger.debug("Start the bundle deployment")

        bundle_parser = BundleParser(bundle_data)

        # generate a new bundle ID
        # [a-z] user_id timestamp
        import random
        import string
        import time
        bundle_id = ''.join([random.choice(string.ascii_lowercase), self.user_id, str(int(time.time() * 1000))])
        # replace all service names
        for service_name in list(bundle_parser.listservices()):
            service_id = ''.join([bundle_id, service_name])
            bundle_parser.setservicename(service_name, service_id)

        # adding entry to the database for the bundle
        bundle = Bundle(bundle_id, self.user_id, str(bundle_data))
        self.dbsession.add(bundle)

         # Deploy services
        self.logger.info("Deploying services for the bundle")
        for service_name in bundle_parser.listservices():
            service_charm = bundle_parser.getcharmname(service_name)
            service_units = bundle_parser.getnumberunits(service_name)

            # deploy the service for the given charm
            self.logger.debug("Deploying the service (%s) with the charm (%s) with (%s) unit(s)",
                              service_name, service_charm, service_units)
            self.logger.debug(self.juju_communication.deployservice(service_name, service_charm,
                                                                    num_units=service_units))

            if bundle_parser.isexposed(service_name):
                self.logger.debug("Exposing the service (%s)", service_name)
                self.logger.debug(self.juju_communication.expose(service_name))

            # adding entry to the database for the service
            self.logger.debug("Adding entry to the database")
            service = Service(service_name, bundle_id, service_units)
            self.dbsession.add(service)

        # Create relations
        self.logger.info("Deploying relations for the bundle")
        for relations in bundle_parser.getrelations():
            if len(relations) == 2:
                # add relation
                self.logger.debug("Adding relation between (%s and %s)", relations[0], relations[1])
                self.logger.debug(self.juju_communication.addrelation(relations[0], relations[1]))
            else:
                # skip relation
                self.logger.warn("Incomplete relation detected and won't be added")

        return bundle_id