예제 #1
0
    def test_isexposed(self):
        # is not exposed
        bundle = BundleParser(self.correct)
        self.assertFalse(bundle.isexposed("mysql"))

        # is exposed
        self.assertTrue(bundle.isexposed("wordpress"))
예제 #2
0
    def test_getcharmname(self):
        # no charm
        bundle = BundleParser(self.nocharm)
        self.assertRaises(BundleError, bundle.getcharmname, "mysql")

        # has charm
        bundle = BundleParser(self.correct)
        self.assertIsNotNone(bundle.getcharmname("mysql"))
예제 #3
0
    def test_getnumberunits(self):
        # no units
        bundle = BundleParser(self.nounit)
        self.assertRaises(BundleError, bundle.getnumberunits, "mysql")

        # has units
        bundle = BundleParser(self.correct)
        self.assertEqual(1, bundle.getnumberunits("mysql"))
예제 #4
0
    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()
예제 #5
0
    def test_listservices(self):
        # test no services
        bundle = BundleParser(self.noservice)
        if bundle.listservices():
            self.fail()

        # test services found
        bundle = BundleParser(self.correct)
        if not bundle.listservices():
            self.fail()
예제 #6
0
    def test__serviceexists(self):
        # test bundle no service section
        bundle = BundleParser(self.noservice)
        self.assertFalse(bundle._serviceexists("fake"))

        # test bundle service not found
        bundle = BundleParser(self.correct)
        self.assertFalse(bundle._serviceexists("fake"))

        # test bundle service exists
        self.assertTrue(bundle._serviceexists("mysql"))
예제 #7
0
    def test_getservice(self):
        # test bundle empty
        self.assertRaises(BundleError, BundleParser, self.empty)

        # test bundle no service section
        bundle = BundleParser(self.noservice)
        self.assertRaises(BundleError, bundle.getservice, "fake")

        # test bundle service not found
        bundle = BundleParser(self.correct)
        self.assertRaises(BundleError, bundle.getservice, "fake")

        # test bundle service exists
        self.assertIsNotNone(bundle.getservice("mysql"))
예제 #8
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
예제 #9
0
    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)