예제 #1
0
def bootstrap_jenkins():
    status_set("maintenance", "Bootstrapping Jenkins configuration")
    service = Service()
    service.check_ready()
    configuration = Configuration()
    configuration.bootstrap()
    set_state("jenkins.bootstrapped")
예제 #2
0
class ServiceTest(CharmTest):

    def setUp(self):
        super().setUp()
        self.service = Service()

    def test_check_ready(self):
        """
        If the service is ready, no exception is raised.
        """
        self.fakes.network.get("http://localhost:8080", status_code=403)
        self.assertIsNone(self.service.check_ready())

    def test_check_ready_transient_failure(self):
        """
        Transient failures are retried.
        """
        start = time.time()

        def callback(requests, context):
            if time.time() - start >= 2:
                context.status_code = 503
            else:
                context.status_code = 200
            return ""

        self.fakes.network.get(URL, text=callback)
        self.assertIsNone(self.service.check_ready())

    def test_check_ready_unavailable(self):
        """
        If the backend keeps returning 5xx, an error is raised.
        """
        self.fakes.network.get(URL, status_code=500)
        self.assertRaises(ServiceUnavailable, self.service.check_ready)
예제 #3
0
def bootstrap_jenkins():
    status_set("maintenance", "Bootstrapping Jenkins configuration")
    service = Service()
    service.check_ready()
    configuration = Configuration()
    configuration.bootstrap()
    set_state("jenkins.bootstrapped")
예제 #4
0
def set_jenkins_dir(storage_dir=paths.HOME):
    status_set("maintenance", "Configuring Jenkins storage")
    jenkins_installed = get_state("apt.installed.jenkins")
    if jenkins_installed:
        service_stop('jenkins')

    if storage_dir is paths.HOME:
        log("Setting Jenkins to use local storage")
        Storage().unlink_home()
    else:
        log("Setting Jenkins to use storage at {}".format(storage_dir))
        Storage().link_home(storage_dir)

    if jenkins_installed:
        status_set("maintenance", "Restarting Jenkins")
        service_start('jenkins')
        Service().check_ready()

    if get_state('jenkins.bootstrapped'):
        # JENKINS_HOME just changed trigger bootstrap again
        remove_state("jenkins.bootstrapped")
        bootstrap_jenkins()
    else:
        status_set('active', 'Ready')
예제 #5
0
 def setUp(self):
     super().setUp()
     self.service = Service()