Beispiel #1
0
 def test_save_creates_hash(self):
     release = Release(build=self.build,
                       env_yaml=self.env,
                       config_yaml=self.config,
                       volumes=self.volumes)
     release.save()
     assert release.hash  # must not be None or blank.
Beispiel #2
0
    def test_swarm_creates_release(self):

        # Make an existing release to save with the swarm.
        squad = Squad(name=randchars())
        squad.save()

        release = Release(build=self.build,
                          env_yaml=self.env,
                          config_yaml=self.config,
                          volumes=self.volumes)
        release.save()

        release_count = Release.objects.count()

        swarm = Swarm(app=self.app,
                      release=release,
                      config_name=randchars(),
                      proc_name=randchars(),
                      squad=squad,
                      size=1,
                      config_yaml=self.config,
                      env_yaml=self.env,
                      volumes=self.volumes)
        swarm.save()

        # update the swarm with new config.
        swarm.config_yaml = self.config.update({'c': 3})
        swarm.save()

        # get_current_release should make a new release for us from the new
        # config.
        r = swarm.get_current_release(self.version)
        assert Release.objects.count() == release_count + 1
        assert r.id != release.id
Beispiel #3
0
class TestDeploy(object):
    def setup(self):
        self.app = App(name=randchars(), repo_url=randchars(), repo_type='hg')
        self.app.save()

        self.version = 'v1'
        self.build = Build(app=self.app,
                           start_time=timezone.now(),
                           end_time=timezone.now(),
                           tag=self.version,
                           status='success',
                           buildpack_url=randchars(),
                           buildpack_version=randchars(),
                           hash=randchars())
        self.build.file = '%s/build.tar.gz' % randchars()
        self.build.save()

        self.env = {'a': 1}
        self.config = {'b': 2, 'tricky_value': "@We're testing, aren't we?"}
        self.volumes = [['/blah', '/blerg']]
        self.release = Release(build=self.build,
                               env_yaml=self.env,
                               config_yaml=self.config,
                               volumes=self.volumes)
        self.release.save()

    def test_build_proc_info(self, gridfs):
        info = build_proc_info(self.release, 'test', 'somehost', 'web', 8000)
        assert info['volumes'] == self.volumes

    def test_build_proc_yaml_file(self, gridfs):
        # Test that the proc.yaml file that gets deployed has the correct
        # information.

        config_name = 'test'
        hostname = 'somehost'
        proc = 'web'
        port = 8000

        with tmpdir():
            # Generate the proc.yaml file the same way that
            # server.vr.server.tasks.deploy() does; then yaml.load() it
            # and compare with the local info.
            with io.open('proc.yaml', 'w+') as f:
                info = build_proc_info(self.release, config_name, hostname,
                                       proc, port)
                yaml.safe_dump(info,
                               stream=f,
                               default_flow_style=False,
                               encoding=None)

                f.seek(0)
                written_info = yaml.load(f.read())

        assert info == written_info
Beispiel #4
0
    def test_new_osimage_invalidates_release(self):
        # If you have a swarm with a current release, and you get a new OS
        # image on the app's stack, then call get_current_release on the swarm,
        # it should give you a new release with a build linked to the new OS
        # image.
        squad = Squad(name=randchars())
        squad.save()

        release = Release(build=self.build,
                          env_yaml=self.env,
                          config_yaml=self.config,
                          volumes=self.volumes)
        release.save()

        swarm = Swarm(app=self.app,
                      release=release,
                      config_name=randchars(),
                      proc_name=randchars(),
                      squad=squad,
                      size=1,
                      config_yaml=self.config,
                      env_yaml=self.env,
                      volumes=self.volumes)
        swarm.save()

        assert swarm.get_current_release(self.version) == release

        # Now save a new OS Image to the stack, and assert that we get a new
        # release.
        new_image = OSImage(name=randchars(),
                            file=randchars(),
                            stack=self.stack,
                            active=True)
        with mock.patch.object(OSImage,
                               '_compute_file_md5',
                               return_value='abcdef1234567890'):
            new_image.save()

        new_release = swarm.get_current_release(self.version)
        assert new_release != release

        assert new_release.build.os_image == new_image
Beispiel #5
0
    def test_swarm_with_stack_reuses_release(self):
        squad = Squad(name=randchars())
        squad.save()

        release = Release(build=self.build,
                          env_yaml=self.env,
                          config_yaml=self.config,
                          volumes=self.volumes)
        release.save()

        swarm = Swarm(app=self.app,
                      release=release,
                      config_name=randchars(),
                      proc_name=randchars(),
                      squad=squad,
                      size=1,
                      config_yaml=self.config,
                      env_yaml=self.env,
                      volumes=self.volumes)
        swarm.save()

        assert swarm.get_current_release(self.version) == release
Beispiel #6
0
    def setup(self):
        self.app = App(name=randchars(), repo_url=randchars(), repo_type='hg')
        self.app.save()

        self.version = 'v1'
        self.build = Build(app=self.app,
                           start_time=timezone.now(),
                           end_time=timezone.now(),
                           tag=self.version,
                           status='success',
                           buildpack_url=randchars(),
                           buildpack_version=randchars(),
                           hash=randchars())
        self.build.file = '%s/build.tar.gz' % randchars()
        self.build.save()

        self.env = {'a': 1}
        self.config = {'b': 2, 'tricky_value': "@We're testing, aren't we?"}
        self.volumes = [['/blah', '/blerg']]
        self.release = Release(build=self.build,
                               env_yaml=self.env,
                               config_yaml=self.config,
                               volumes=self.volumes)
        self.release.save()
Beispiel #7
0
    def test_swarm_without_stack_reuses_release(self):
        self.app = App(name=randchars(), repo_url=randchars(), repo_type='hg')
        self.app.save()

        self.build = Build(app=self.app,
                           os_image=None,
                           start_time=timezone.now(),
                           end_time=timezone.now(),
                           tag=self.version,
                           status='success',
                           buildpack_url=randchars(),
                           buildpack_version=randchars(),
                           hash=randchars())
        self.build.save()

        squad = Squad(name=randchars())
        squad.save()

        release = Release(build=self.build,
                          env_yaml=self.env,
                          config_yaml=self.config,
                          volumes=self.volumes)
        release.save()

        swarm = Swarm(app=self.app,
                      release=release,
                      config_name=randchars(),
                      proc_name=randchars(),
                      squad=squad,
                      size=1,
                      config_yaml=self.config,
                      env_yaml=self.env,
                      volumes=self.volumes)
        swarm.save()

        assert swarm.get_current_release(self.version) == release
Beispiel #8
0
 def test_release_eq_empty_config(self):
     r = Release(build=self.build)
     assert release_eq(r, {}, {}, [])
Beispiel #9
0
 def test_release_not_eq(self):
     r = Release(build=self.build,
                 env_yaml=self.env,
                 config_yaml=self.config,
                 volumes=self.volumes)
     assert not release_eq(r, {'no': 'match'}, self.env, self.volumes)
Beispiel #10
0
 def test_release_eq(self):
     r = Release(build=self.build,
                 env_yaml=self.env,
                 config_yaml=self.config,
                 volumes=self.volumes)
     assert release_eq(r, self.config, self.env, self.volumes)