def test_create_zipfile(self):
     archive = Archive('test.zip')
     archive._runtime = RUNTIME_NODE_JS
     ok_(hasattr(archive.create_zipfile(), 'read'))
     with PyZipFile(archive._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
         ok_('lambda_function.pyc' in zipfile.namelist())
         ok_('.lamvery_secret.json' in zipfile.namelist())
Exemple #2
0
 def test_create_zipfile(self):
     archive = Archive('test.zip')
     ok_(hasattr(archive.create_zipfile(), 'read'))
     with PyZipFile(archive._zippath, 'r',
                    compression=ZIP_DEFLATED) as zipfile:
         ok_('lambda_function.pyc' in zipfile.namelist())
         ok_('.lamvery_secret.json' in zipfile.namelist())
Exemple #3
0
 def test_archive_file(self):
     archive = Archive('test.zip')
     archive._archive_file(
         self.zipfile, os.path.join(self.pj_root, 'setup.py'))
     ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))
     archive._archive_file(
         self.zipfile, os.path.join(self.pj_root, 'README.md'))
     ok_(isinstance(self.zipfile.getinfo('README.md'), zipfile.ZipInfo))
Exemple #4
0
 def test_create_zipfile_with_single_file(self):
     archive = Archive('test.zip',
                       function_filename='lambda_function.py',
                       single_file=True)
     archive.create_zipfile()
     with PyZipFile(archive._zippath, 'r',
                    compression=ZIP_DEFLATED) as zipfile:
         ok_('lambda_function.py' in zipfile.namelist())
         ok_(not ('.lamvery_secret.json' in zipfile.namelist()))
Exemple #5
0
 def action(self):
     archive_name = self._config.get_archive_name()
     function_filename = self._config.get_function_filename()
     secret = self._config.generate_lambda_secret()
     exclude = self._config.get_exclude()
     archive = Archive(filename=archive_name,
                       function_filename=function_filename,
                       secret=secret,
                       single_file=self._single_file,
                       no_libs=self._no_libs,
                       exclude=exclude)
     zipfile = archive.create_zipfile()
     with open(archive_name, 'w') as f:
         f.write(zipfile.read())
     zipfile.close()
     self._logger.info('Output archive(zip) to {}'.format(archive_name))
Exemple #6
0
 def action(self):
     archive_name = self._config.get_archive_name()
     function_filename = self._config.get_function_filename()
     secret = self._config.generate_lambda_secret()
     exclude = self._config.get_exclude()
     archive = Archive(filename=archive_name,
                       function_filename=function_filename,
                       secret=secret,
                       single_file=self._single_file,
                       no_libs=self._no_libs,
                       exclude=exclude,
                       runtime=self._config.get_runtime())
     zipfile = archive.create_zipfile()
     with open(archive_name, 'w') as f:
         f.write(zipfile.read())
     zipfile.close()
     self._logger.info('Output archive(zip) to {}'.format(archive_name))
Exemple #7
0
 def test_archive_file(self):
     archive = Archive('test.zip')
     archive._archive_file(self.zipfile,
                           os.path.join(self.pj_root, 'setup.py'))
     ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))
     archive._archive_file(self.zipfile,
                           os.path.join(self.pj_root, 'README.md'))
     ok_(isinstance(self.zipfile.getinfo('README.md'), zipfile.ZipInfo))
Exemple #8
0
    def test_get_paths(self):
        archive = Archive('test.zip')
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)

        archive = Archive('test.zip', no_libs=True)
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)
        ok_(os.path.join(self.pj_root, 'lambda_function.py') in paths)
        ok_(os.path.join(self.pj_root, 'lambda_function.pyc') in paths)
        ok_(os.path.join(self.pj_root, '.lamvery.yml') in paths)

        archive = Archive('test.zip', function_filename='test.py', single_file=True)
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'test.py') in paths)
        ok_(not os.path.join(self.pj_root, 'lambda_function.pyc') in paths)
        ok_(not os.path.join(self.pj_root, '.lamvery.yml') in paths)

        del os.environ['VIRTUAL_ENV']
        archive = Archive('test.zip')
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)
Exemple #9
0
 def test_is_exclude(self):
     archive = Archive('test.zip', exclude=['^\.lamvery\.yml$'])
     eq_(archive.is_exclude('foo.txt'), False)
     eq_(archive.is_exclude('.lamvery.yml'), True)
Exemple #10
0
 def test_is_exclude_dir(self):
     archive = Archive('test.zip')
     eq_(archive.is_exclude_dir('.git'), True)
     eq_(archive.is_exclude_dir('foo'), False)
     archive.is_exclude = Mock(return_value=True)
     eq_(archive.is_exclude_file('foo'), True)
Exemple #11
0
 def test_get_size(self):
     archive = Archive('test.zip')
     archive.create_zipfile()
     ok_(isinstance(archive.get_size(), int))
Exemple #12
0
 def test_archive_single_file(self):
     self._single_file = True
     archive = Archive('test.zip', single_file=True)
     archive._archive_file(
         self.zipfile, os.path.join(self.pj_root, 'setup.py'))
     ok_(isinstance(self.zipfile.getinfo('setup.py'), zipfile.ZipInfo))
Exemple #13
0
 def test_create_zipfile_with_single_file(self):
     archive = Archive('test.zip', function_filename='lambda_function.py', single_file=True)
     archive.create_zipfile()
     with PyZipFile(archive._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
         ok_('lambda_function.py' in zipfile.namelist())
         ok_(not ('.lamvery_secret.json' in zipfile.namelist()))
Exemple #14
0
 def test_archive_dir(self):
     archive = Archive('test.zip')
     archive._archive_dir(self.zipfile, self.pj_root)
     ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))
Exemple #15
0
    def action(self):
        archive_name = self._config.get_archive_name()
        function_filename = self._config.get_function_filename()
        secret = self._config.generate_lambda_secret()
        exclude = self._config.get_exclude()
        archive = Archive(filename=archive_name,
                          function_filename=function_filename,
                          secret=secret,
                          single_file=self._single_file,
                          no_libs=self._no_libs,
                          exclude=exclude)
        func_name = self._config.get_function_name()
        local_conf = self._config.get_configuration()
        zipfile = archive.create_zipfile()
        client = self.get_client()
        remote_conf = client.get_function_conf(func_name)
        alias_name = self._set_alias.get_alias_name()
        remote_size = client.calculate_capacity()
        local_size = archive.get_size()
        new_version = None
        cur_version = None

        if len(remote_conf) == 0:
            self._logger.warn(
                '[Function] Create new function "{}"'.format(func_name))

        self._print_diff(prefix='[Function]',
                         remote=remote_conf,
                         local=local_conf,
                         keys=CONF_DIFF_KEYS)

        if len(remote_conf) > 0:

            if self._enable_versioning():
                cur_version = client.get_alias(
                    func_name, alias_name).get('FunctionVersion')
            else:
                local_size -= remote_conf['CodeSize']

            client.update_function_conf(local_conf)
            self._print_capacity(remote=remote_size, local=local_size)
            new_version = client.update_function_code(
                zipfile, local_conf, self._enable_versioning())

        else:
            if self._enable_versioning():
                local_size *= 2

            self._print_capacity(remote=remote_size, local=local_size)
            new_version = client.create_function(zipfile, local_conf,
                                                 self._enable_versioning())

        zipfile.close()

        if new_version is not None:
            self._logger.info(
                '[Function] Deployed version: {}'.format(new_version))

        if cur_version is not None:
            self._logger.info(
                '[Function] Previous version: {}'.format(cur_version))
            self._set_alias._alias = previous_alias(alias_name)
            self._set_alias._version = cur_version
            self._set_alias.action()

        if alias_name is not None:
            self._set_alias._alias = alias_name
            self._set_alias._version = new_version
            self._set_alias.action()
Exemple #16
0
 def test_is_exclude_dir(self):
     archive = Archive('test.zip')
     eq_(archive.is_exclude_dir('.git'), True)
     eq_(archive.is_exclude_dir('foo'), False)
     archive.is_exclude = Mock(return_value=True)
     eq_(archive.is_exclude_file('foo'), True)
Exemple #17
0
 def test_archive_dir(self):
     archive = Archive('test.zip')
     archive._archive_dir(self.zipfile, self.pj_root)
     ok_(isinstance(self.zipfile.getinfo('setup.pyc'), zipfile.ZipInfo))
 def test_archive_dist(self):
     archive = Archive('test.zip')
     archive._archive_dist(self.zipfile, 'lamvery.js')
     ok_(isinstance(self.zipfile.getinfo('lamvery.js'), zipfile.ZipInfo))
Exemple #19
0
 def test_archive_single_file(self):
     self._single_file = True
     archive = Archive('test.zip', single_file=True)
     archive._archive_file(self.zipfile,
                           os.path.join(self.pj_root, 'setup.py'))
     ok_(isinstance(self.zipfile.getinfo('setup.py'), zipfile.ZipInfo))
Exemple #20
0
    def test_get_paths(self):
        archive = Archive('test.zip')
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)

        archive = Archive('test.zip', no_libs=True)
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)
        ok_(os.path.join(self.pj_root, 'lambda_function.py') in paths)
        ok_(os.path.join(self.pj_root, 'lambda_function.pyc') in paths)
        ok_(os.path.join(self.pj_root, '.lamvery.yml') in paths)

        archive = Archive('test.zip',
                          function_filename='test.py',
                          single_file=True)
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'test.py') in paths)
        ok_(not os.path.join(self.pj_root, 'lambda_function.pyc') in paths)
        ok_(not os.path.join(self.pj_root, '.lamvery.yml') in paths)

        del os.environ['VIRTUAL_ENV']
        archive = Archive('test.zip')
        paths = archive._get_paths()
        ok_(os.path.join(self.pj_root, 'lamvery') in paths)
Exemple #21
0
 def test_is_source_file(self):
     archive = Archive('test.zip')
     eq_(archive.is_source_file('foo.py'), True)
     eq_(archive.is_source_file('foo.pyc'), True)
     eq_(archive.is_source_file('foo.php'), False)
Exemple #22
0
 def test_is_source_file(self):
     archive = Archive('test.zip')
     eq_(archive.is_source_file('foo.py'), True)
     eq_(archive.is_source_file('foo.pyc'), True)
     eq_(archive.is_source_file('foo.php'), False)
Exemple #23
0
 def test_get_size(self):
     archive = Archive('test.zip')
     archive.create_zipfile()
     ok_(isinstance(archive.get_size(), int))
Exemple #24
0
    def action(self):
        archive_name = self._config.get_archive_name()
        function_filename = self._config.get_function_filename()
        secret = self._config.generate_lambda_secret()
        exclude = self._config.get_exclude()
        archive = Archive(filename=archive_name,
                          function_filename=function_filename,
                          secret=secret,
                          single_file=self._single_file,
                          no_libs=self._no_libs,
                          exclude=exclude)
        func_name = self._config.get_function_name()
        local_conf = self._config.get_configuration()
        zipfile = archive.create_zipfile()
        client = self.get_client()
        remote_conf = client.get_function_conf(func_name)
        alias_name = self._set_alias.get_alias_name()
        remote_size = client.calculate_capacity()
        local_size = archive.get_size()
        new_version = None
        cur_version = None

        if len(remote_conf) == 0:
            self._logger.warn(
                '[Function] Create new function "{}"'.format(func_name))

        self._print_diff(
            prefix='[Function]',
            remote=remote_conf, local=local_conf, keys=CONF_DIFF_KEYS)

        if len(remote_conf) > 0:

            if self._enable_versioning():
                cur_version = client.get_alias(
                    func_name, alias_name).get('FunctionVersion')
            else:
                local_size -= remote_conf['CodeSize']

            client.update_function_conf(local_conf)
            self._print_capacity(remote=remote_size, local=local_size)
            new_version = client.update_function_code(
                zipfile, local_conf, self._enable_versioning())

        else:
            if self._enable_versioning():
                local_size *= 2

            self._print_capacity(
                remote=remote_size, local=local_size)
            new_version = client.create_function(
                zipfile, local_conf, self._enable_versioning())

        zipfile.close()

        if new_version is not None:
            self._logger.info(
                '[Function] Deployed version: {}'.format(new_version))

        if cur_version is not None:
            self._logger.info(
                '[Function] Previous version: {}'.format(cur_version))
            self._set_alias._alias = previous_alias(alias_name)
            self._set_alias._version = cur_version
            self._set_alias.action()

        if alias_name is not None:
            self._set_alias._alias = alias_name
            self._set_alias._version = new_version
            self._set_alias.action()
Exemple #25
0
 def test_is_exclude(self):
     archive = Archive('test.zip', exclude=['^\.lamvery\.yml$'])
     eq_(archive.is_exclude('foo.txt'), False)
     eq_(archive.is_exclude('.lamvery.yml'), True)