コード例 #1
0
ファイル: tasks.py プロジェクト: elboby/garnison-1
def package_build_process(name, url, branch, path_to_missile=None,
                          domain=None, stack=None):
    """
    Prepare working copy, checkout working copy, build
    """
    logfilename = "build-%s-%s-%s.log" % (name, branch, datetime.datetime.utcnow().isoformat())
    logfilepath = os.path.join(dd.BUILD_LOGPATH, logfilename)
    sys.stdout = open(logfilepath, "w")
    sys.stderr = sys.stdout

    args = ["name", "url", "branch", "path_to_missile"]
    for arg in args:
        print arg , ": ", locals()[arg]

    with settings(host_string=host, key_filename=key_filename):
        wc = WorkingCopy(name, base_folder="/var/gachette")
        wc.prepare_environment()
        wc.checkout_working_copy(url=url, branch=branch)

        latest_version = RedisBackend().get_latest_version(name)
        new_base_version = RedisBackend().get_new_base_version(name)
        new_version = wc.get_version_from_git(base_version=new_base_version)
        # skipping existing build removed
        new_version += "-%s" % branch
        wc.set_version(app=new_version, env=new_version, service=new_version)
        result = wc.build(output_path="/var/gachette/debs", path_to_missile=path_to_missile)
        RedisBackend().delete_lock("packages", name)
        RedisBackend().create_package(name, new_version, result)
        print "Built new:", name, branch, new_version

    if domain is not None and stack is not None:
        RedisBackend().add_stack_package(domain, stack, name, new_version)
        print "Added to 'domains:%s:stacks:%s:packages' as {'%s': '%s'}" % (domain, stack, name, new_version)
コード例 #2
0
ファイル: tasks_old.py プロジェクト: elboby/garnison-1
def final_build_process(name, app_version, env_version, service_version, path_to_missile=None, webcallback=None):
    """
    launch build
    """
    args = ["name", "app_version", "env_version", "service_version", "path_to_missile", "webcallback"]
    for arg in args:
        print arg , ": ", locals()[arg]
    with settings(host_string=host, key_filename=key_filename):
        wc = WorkingCopy(name, base_folder="/var/gachette")
        wc.set_version(app=app_version, 
                    # env=env_version, 
                    # service=service_version,
                    )
        wc.build(output_path="/var/gachette/debs", path_to_missile=path_to_missile, webcallback=webcallback)
        send_notification("WorkingCopy #%s build launched" % name)
コード例 #3
0
ファイル: tasks_old.py プロジェクト: elboby/garnison-1
def checkout_build_process(name, url, branch, app_version, env_version, service_version, path_to_missile=None, webcallback=None):
    """
    Prepare working copy
    """
    args = ["name", "url", "branch", "app_version", "env_version", "service_version", "path_to_missile", "webcallback"]
    for arg in args:
        print arg , ": ", locals()[arg]
    with settings(host_string=host, key_filename=key_filename):
        wc = WorkingCopy(name, base_folder="/var/gachette")
        wc.prepare_environment()
        wc.checkout_working_copy(url=url, branch=branch)
        # TODO retrieve list of package
    send_notification("WorkingCopy #%s updated with %s" % (name, branch))

    # call next step async
    final_build_process.delay(name, app_version, env_version, service_version, path_to_missile, webcallback)
コード例 #4
0
class GitVersionTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("version_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.working_copy.get_current_git_hash',
                return_value="1A2B3C4D")
    def test_basic(self, git_hash_mock):
        version = self.wc.get_version_from_git()
        self.assertEqual(version, '0.0.1rev1A2B3C4D',
                         "Wrong version given %s" % version)

        version = self.wc.get_version_from_git(suffix="foo")
        self.assertEqual(version, '0.0.1rev1A2B3C4D-foo',
                         "Wrong version given %s" % version)

        version = self.wc.get_version_from_git(suffix="foo_bar")
        self.assertEqual(version, '0.0.1rev1A2B3C4D-foo-bar',
                         "Wrong version given %s" % version)
コード例 #5
0
ファイル: test_working_copy.py プロジェクト: elboby/gachette
class GitVersionTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("version_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.working_copy.get_current_git_hash', return_value="1A2B3C4D")
    def test_basic(self, git_hash_mock):
        version = self.wc.get_version_from_git()
        self.assertEqual(version,
                        '0.0.1rev1A2B3C4D',
                        "Wrong version given %s" % version)

        version = self.wc.get_version_from_git(suffix="foo")
        self.assertEqual(version,
                        '0.0.1rev1A2B3C4D-foo',
                        "Wrong version given %s" % version)

        version = self.wc.get_version_from_git(suffix="foo_bar")
        self.assertEqual(version,
                        '0.0.1rev1A2B3C4D-foo-bar',
                        "Wrong version given %s" % version)
コード例 #6
0
class BuildTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("build_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.working_copy.run')
    def test_build(self, fabric_run_mock):
        app_version = '1.1.0'
        webcallback = 'http://garnison.dev:8080/stacks/1234/build_cb'
        self.wc.set_version(app=app_version)
        self.wc.build('/var/gachette/debs', webcallback=webcallback)

        fabric_run_mock.assert_has_calls(
                [mock.call('trebuchet build %s --arch amd64 --output %s %s %s' \
                    % (os.path.join(self.wc.working_copy, '.missile.yml'),
                       '/var/gachette/debs',
                       self.wc.get_version_suffix(),
                       self.wc.get_webcallback_suffix(webcallback)))])
コード例 #7
0
ファイル: test_working_copy.py プロジェクト: elboby/gachette
class BuildTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("build_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.working_copy.run')
    def test_build(self, fabric_run_mock):
        app_version = '1.1.0'
        webcallback = 'http://garnison.dev:8080/stacks/1234/build_cb'
        self.wc.set_version(app=app_version)
        self.wc.build('/var/gachette/debs', webcallback=webcallback)

        fabric_run_mock.assert_has_calls(
                [mock.call('trebuchet build %s --arch amd64 --output %s %s %s' \
                    % (os.path.join(self.wc.working_copy, '.missile.yml'),
                       '/var/gachette/debs',
                       self.wc.get_version_suffix(),
                       self.wc.get_webcallback_suffix(webcallback)))])
コード例 #8
0
 def setUp(self):
     self.wc = WorkingCopy("version_test")
コード例 #9
0
class VersionTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("version_test")

    def tearDown(self):
        self.wc = None

    def test_app_version(self):
        self.wc.set_version(app='1.2.3')
        self.assertEqual(
            self.wc.get_version_suffix(), " --app-version 1.2.3",
            "app version is not well recognized (%s)" %
            self.wc.get_version_suffix())

        self.wc.set_version(app='1.2.4')
        self.assertEqual(
            self.wc.get_version_suffix(), " --app-version 1.2.4",
            "app version is updated properly (%s)" %
            self.wc.get_version_suffix())

        self.wc.set_version(app='')
        self.assertEqual(
            self.wc.get_version_suffix(), "",
            "app version is removed properly (%s)" %
            self.wc.get_version_suffix())

    def test_env_version(self):
        self.wc.set_version(env='1.2.3')
        self.assertEqual(
            self.wc.get_version_suffix(), " --env-version 1.2.3",
            "env version is not well recognized (%s)" %
            self.wc.get_version_suffix())

    def test_service_version(self):
        self.wc.set_version(service='1.2.3')
        self.assertEqual(
            self.wc.get_version_suffix(), " --service-version 1.2.3",
            "service version is not well recognized (%s)" %
            self.wc.get_version_suffix())

    def test_multiple_version(self):
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(
            self.wc.get_version_suffix(),
            " --app-version 1.2.3 --env-version 2.3.4",
            "env and app version are not well recognized (%s)" %
            self.wc.get_version_suffix())
        self.wc.set_version(service='3.4.5')
        self.assertEqual(
            self.wc.get_version_suffix(),
            " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5",
            "service, env and app version are not well recognized (%s)" %
            self.wc.get_version_suffix())

    def test_all_version(self):
        self.wc.set_version(service='3.4.5')
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(
            self.wc.get_version_suffix(),
            " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5",
            "service, env and app version are sorted properly (%s)" %
            self.wc.get_version_suffix())
コード例 #10
0
 def setUp(self):
     self.wc = WorkingCopy("build_test")
コード例 #11
0
 def setUp(self):
     self.wc = WorkingCopy("prepare_test")
コード例 #12
0
class PrepareTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("prepare_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.utils.run', return_value=run_failed(True))
    def test_prepare_environment_default(self, utils_run_mock):
        """
        Prepare not existing folder
        """
        folder = self.wc.working_copy
        self.wc.prepare_environment()

        utils_run_mock.assert_has_calls([
            mock.call("test -d %s" % folder),
            mock.call("mkdir -p %s" % folder)
        ])

    @mock.patch('gachette.lib.utils.run', return_value=run_failed(False))
    def test_prepare_environment_existing(self, utils_run_mock):
        """
        Prepare existing folder
        """
        folder = self.wc.working_copy
        self.wc.prepare_environment()

        utils_run_mock.assert_has_calls([
            mock.call("test -d %s" % folder),
            mock.call("rm -rf %s/*" % folder)
        ])

    @mock.patch('gachette.lib.working_copy.run', return_value=run_failed(True))
    def test_checkout_clone(self, fabric_run_mock):
        # This URL does not exist. For test only
        folder = self.wc.working_copy
        url = 'https://github.com/organizations/gachette/test_project'
        branch = 'origin/test-branch'
        self.wc.checkout_working_copy(url, branch)

        fabric_run_mock.assert_has_calls([
            mock.call('test -d %s/.git' % folder),
            mock.call('git clone --depth=100 --quiet %s %s' % (url, folder)),
            mock.call('git fetch --quiet origin'),
            mock.call('git reset --quiet --hard %s' % branch),
            mock.call('git submodule --quiet init'),
            mock.call('git submodule --quiet update'),
            mock.call('git rev-parse HEAD')
        ])

    @mock.patch('gachette.lib.working_copy.run',
                return_value=run_failed(False))
    def test_checkout_update(self, fabric_run_mock):
        # This URL does not exist. For test only
        folder = self.wc.working_copy
        url = 'https://github.com/organizations/gachette/test_project'
        branch = 'origin/test-branch'
        self.wc.checkout_working_copy(url, branch)

        fabric_run_mock.assert_has_calls([
            mock.call('test -d %s/.git' % folder),
            mock.call('git fetch --quiet origin'),
            mock.call('git reset --quiet --hard %s' % branch),
            mock.call('git submodule --quiet init'),
            mock.call('git submodule --quiet update'),
            mock.call('git rev-parse HEAD')
        ])
コード例 #13
0
ファイル: test_working_copy.py プロジェクト: elboby/gachette
 def setUp(self):
     self.wc = WorkingCopy("build_test")
コード例 #14
0
ファイル: test_working_copy.py プロジェクト: elboby/gachette
 def setUp(self):
     self.wc = WorkingCopy("prepare_test")
コード例 #15
0
ファイル: test_working_copy.py プロジェクト: elboby/gachette
class PrepareTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("prepare_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.utils.run', return_value=run_failed(True))
    def test_prepare_environment_default(self, utils_run_mock):
        """
        Prepare not existing folder
        """
        folder = self.wc.working_copy
        self.wc.prepare_environment()

        utils_run_mock.assert_has_calls(
                                [mock.call("test -d %s" % folder),
                                 mock.call("mkdir -p %s" % folder)])

    @mock.patch('gachette.lib.utils.run', return_value=run_failed(False))
    def test_prepare_environment_existing(self, utils_run_mock):
        """
        Prepare existing folder
        """
        folder = self.wc.working_copy
        self.wc.prepare_environment()

        utils_run_mock.assert_has_calls(
                            [mock.call("test -d %s" % folder),
                             mock.call("rm -rf %s/*" % folder)])

    @mock.patch('gachette.lib.working_copy.run', return_value=run_failed(True))
    def test_checkout_clone(self, fabric_run_mock):
        # This URL does not exist. For test only
        folder = self.wc.working_copy
        url = 'https://github.com/organizations/gachette/test_project'
        branch = 'test-branch'
        self.wc.checkout_working_copy(url, branch)

        fabric_run_mock.assert_has_calls(
                [mock.call('test -d %s/.git' % folder),
                 mock.call('git clone --depth=100 --quiet %s %s' % (url, folder)),
                 mock.call('git fetch --quiet origin'),
                 mock.call('git reset --quiet --hard origin/%s' % branch),
                 mock.call('git submodule --quiet init'),
                 mock.call('git submodule --quiet update'),
                 mock.call('git rev-parse HEAD')])

    @mock.patch('gachette.lib.working_copy.run', return_value=run_failed(False))
    def test_checkout_update(self, fabric_run_mock):
        # This URL does not exist. For test only
        folder = self.wc.working_copy
        url = 'https://github.com/organizations/gachette/test_project'
        branch = 'test-branch'
        self.wc.checkout_working_copy(url, branch)

        fabric_run_mock.assert_has_calls(
                [mock.call('test -d %s/.git' % folder),
                 mock.call('git fetch --quiet origin'),
                 mock.call('git reset --quiet --hard origin/%s' % branch),
                 mock.call('git submodule --quiet init'),
                 mock.call('git submodule --quiet update'),
                 mock.call('git rev-parse HEAD')])
コード例 #16
0
ファイル: test_working_copy.py プロジェクト: elboby/gachette
 def setUp(self):
     self.wc = WorkingCopy("version_test")
コード例 #17
0
ファイル: test_working_copy.py プロジェクト: elboby/gachette
class VersionTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("version_test")

    def tearDown(self):
        self.wc = None

    def test_app_version(self):
        self.wc.set_version(app='1.2.3')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3", 
                        "app version is not well recognized (%s)" % self.wc.get_version_suffix())

        self.wc.set_version(app='1.2.4')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.4", 
                        "app version is updated properly (%s)" % self.wc.get_version_suffix())

        self.wc.set_version(app='')
        self.assertEqual(self.wc.get_version_suffix(), "",
                        "app version is removed properly (%s)" % self.wc.get_version_suffix())

    def test_env_version(self):
        self.wc.set_version(env='1.2.3')
        self.assertEqual(self.wc.get_version_suffix(), " --env-version 1.2.3", 
                        "env version is not well recognized (%s)" % self.wc.get_version_suffix())

    def test_service_version(self):
        self.wc.set_version(service='1.2.3')
        self.assertEqual(self.wc.get_version_suffix(), " --service-version 1.2.3", 
                        "service version is not well recognized (%s)" % self.wc.get_version_suffix())

    def test_multiple_version(self):
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3 --env-version 2.3.4",
                        "env and app version are not well recognized (%s)" % self.wc.get_version_suffix())
        self.wc.set_version(service='3.4.5')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5",
                        "service, env and app version are not well recognized (%s)" % self.wc.get_version_suffix())

    def test_all_version(self):
        self.wc.set_version(service='3.4.5')
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5", 
                        "service, env and app version are sorted properly (%s)" % self.wc.get_version_suffix())