Exemple #1
0
    def test_init(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.prepare_app()
        
        # version
        self.assertEquals(d.version.version, Version('0.1.2').version)

        # app_name
        self.assertEquals(d.app_name, 'testapp')

        # check that that a build_dir has been set up
        build_dir = os.path.join(basepath, d.build_dir)
        self.assertTrue(os.path.exists(build_dir))

        # no deps to install
        self.assertFalse(build_deps.called)

        # update_packages
        update_packages.assert_called_once()

        # now check with no basepath
        d = Deployment('testapp')
        self.assertTrue(basepath in d.build_path)
        
        # now check with basepath without initial slash
        basepath = os.path.join(os.path.dirname(__file__))
        d = Deployment('testapp', base=basepath[1:])
        self.assertTrue(basepath in d.build_path)
Exemple #2
0
    def test_init_with_deps(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath, build_deps=['requests'])
        d.prepare_app()

        # if we supply build_deps then this should be called
        build_deps.assert_called_once()
Exemple #3
0
    def test_init_with_deps(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath, build_deps=['requests'])
        d.prepare_app()

        # if we supply build_deps then this should be called
        build_deps.assert_called_once()
Exemple #4
0
    def test_add_venv_with_requirements(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        req_file = os.path.join(os.path.dirname(__file__),"data", "requirements_test")

        # call _add_venv directly so we can just mock that run out
        d._add_venv(requirements=req_file)
        self.assertTrue('PIP_DOWNLOAD_CACHE' in run.call_args[0][0])
Exemple #5
0
    def test_add_venv_with_requirements(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        req_file = os.path.join(os.path.dirname(__file__), "data",
                                "requirements_test")

        # call _add_venv directly so we can just mock that run out
        d._add_venv(requirements=req_file)
        self.assertTrue('PIP_DOWNLOAD_CACHE' in run.call_args[0][0])
Exemple #6
0
    def test_prepare_app(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.prepare_app()

        # check that sync_app worked
        self.assertTrue(os.path.exists(d.build_path))

        # check that virtualenv was built
        ve_path = os.path.join(d.build_path, d.virtual)
        self.assertTrue(os.path.exists(ve_path))
Exemple #7
0
    def test_prepare_app(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.prepare_app()

        # check that sync_app worked
        self.assertTrue(os.path.exists(d.build_path))

        # check that virtualenv was built
        ve_path = os.path.join(d.build_path, d.virtual)
        self.assertTrue(os.path.exists(ve_path))
Exemple #8
0
    def test_init(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.prepare_app()

        # version
        self.assertEquals(d.version.version, Version('0.1.2').version)

        # app_name
        self.assertEquals(d.app_name, 'testapp')

        # check that that a build_dir has been set up
        build_dir = os.path.join(basepath, d.build_dir)
        self.assertTrue(os.path.exists(build_dir))

        # no deps to install
        self.assertFalse(build_deps.called)

        # update_packages
        update_packages.assert_called_once()

        # now check with no basepath
        d = Deployment('testapp')
        self.assertTrue(basepath in d.build_path)

        # now check with basepath without initial slash
        basepath = os.path.join(os.path.dirname(__file__))
        d = Deployment('testapp', base=basepath[1:])
        self.assertTrue(basepath in d.build_path)
def deb():
    deploy = Deployment(
        env.app_name,
        build_deps=['python-virtualenv', 'python-pip'],
        base='/opt/webapps/wb/flask-native-package',
        arch=distro.Ubuntu(),
        version="0.0.1"
    )

    deploy.add_preinst(['service %s stop' % env.app_name])
    deploy.add_postinst(['service %s start' % env.app_name])
    deploy.prepare_app()

    #this should be built into parcel, or needs an Upstart(Depployment)
    tools.rsync([deploy.path+'/debian/'],deploy.root_path,rsync_ignore='.rsync-ignore')
    deploy.build_package()
Exemple #10
0
    def test_build_rpm(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath, arch=centos)
        d.root_path = os.path.join(basepath, '.parcel')
        d.prepare_app()

        # test build, will not actually call fpm
        d.build_package()
        dest_file = os.path.join(os.path.dirname(__file__), "data",
                                 "testapp_0.1.1-1.noarch.rpm")
        print dest_file
        self.assertTrue(os.path.exists(dest_file))
        os.unlink(dest_file)
Exemple #11
0
 def test_build_rpm(self):
     basepath = os.path.join(os.path.expanduser('~/'))
     d = Deployment('testapp', base=basepath, arch=centos)
     d.root_path = os.path.join(basepath, '.parcel')
     d.prepare_app()
     
     # test build, will not actually call fpm
     d.build_package()
     dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.1-1.noarch.rpm")
     print dest_file
     self.assertTrue(os.path.exists(dest_file))
     os.unlink(dest_file)
def deb():
    deploy = Deployment(
        env.app_name,
        build_deps=["python-virtualenv", "python-pip"],
        base="/opt/pypiserver",
        arch=distro.Ubuntu(),
        version="0.0.1",
    )

    deploy.add_postinst(["service %s start" % env.app_name])
    deploy.prepare_app()

    conf = upstart_conf.format(app_name=env.app_name, app_home=deploy.app_path)
    path = deploy.root_path + "/etc/init/%s.conf" % env.app_name

    tools.write_contents_to_remote(conf, path)
    deploy.build_package()
Exemple #13
0
    def test_build_deb(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.root_path = os.path.join(basepath, '.parcel')
        d.prepare_app()
        
        # test build, will not actually call fpm
        d.build_package()
        dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.2_all.deb")
        self.assertTrue(os.path.exists(dest_file))
        os.unlink(dest_file)

        # now do it without templates to exercise those paths
        d = Deployment('testapp', base=basepath)
        d.root_path = os.path.join(basepath, '.parcel_test')
        d.build_package(templates=False)
        dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.2_all.deb")
        self.assertTrue(os.path.exists(dest_file))
        os.unlink(dest_file)

        # now set some prerm etc directly and check
        d = Deployment('testapp', base=basepath)
        d.root_path = os.path.join(basepath, '.parcel_test')
        lines = ['test line one', 'test line two']
        d.prerm = " ".join(lines)
        d.postrm = " ".join(lines)
        d.preinst = " ".join(lines)
        d.postinst = " ".join(lines)
        d.build_package()
        dest_file = os.path.join(os.path.dirname(__file__),"data", "testapp_0.1.2_all.deb")
        self.assertTrue(os.path.exists(dest_file))
        os.unlink(dest_file)
Exemple #14
0
    def test_deployment(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.prepare_app()

        # check that sync_app worked
        self.assertTrue(os.path.exists(d.build_path))

        # check that virtualenv was built
        ve_path = os.path.join(d.build_path, d.virtual)
        self.assertTrue(os.path.exists(ve_path))

        # check we can add a file
        test_file = os.path.join(os.path.dirname(__file__),"data", "tip.tar.gz")
        d.add_to_root_fs(test_file, 'tip.tar.gz')
        dest_file = os.path.join(d.root_path, "tip.tar.gz")
        self.assertTrue(os.path.exists(dest_file))

        # now check with a leading slash
        d.add_to_root_fs(test_file, '/tip.tar.gz')
        dest_file = os.path.join(d.root_path, "tip.tar.gz")
        self.assertTrue(os.path.exists(dest_file))

        # check we can add data
        data = "this is some test data"
        d.add_data_to_root_fs(data, "test_data.txt")
        dest_file = os.path.join(d.root_path, "test_data.txt")
        self.assertTrue(os.path.exists(dest_file))
        with open(dest_file) as f:
            self.assertEquals(data, f.read())

        # try the same with a leading slash
        data = "this is some test data"
        d.add_data_to_root_fs(data, "/test_data.txt")
        dest_file = os.path.join(d.root_path, "test_data.txt")
        self.assertTrue(os.path.exists(dest_file))
        with open(dest_file) as f:
            self.assertEquals(data, f.read())

        # check we can compile python files
        d.compile_python()
        dest_file = os.path.join(d.build_path, 'data', 'hello.pyc')
        self.assertTrue(os.path.exists(dest_file))

        # check we can clear .py and just leave .pyc files
        d.clear_py_files()
        dest_file = os.path.join(d.build_path, 'data', 'hello.py')
        self.assertFalse(os.path.exists(dest_file))
Exemple #15
0
    def test_build_deb(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.root_path = os.path.join(basepath, '.parcel')
        d.prepare_app()

        # test build, will not actually call fpm
        d.build_package()
        dest_file = os.path.join(os.path.dirname(__file__), "data",
                                 "testapp_0.1.2_all.deb")
        self.assertTrue(os.path.exists(dest_file))
        os.unlink(dest_file)

        # now do it without templates to exercise those paths
        d = Deployment('testapp', base=basepath)
        d.root_path = os.path.join(basepath, '.parcel_test')
        d.build_package(templates=False)
        dest_file = os.path.join(os.path.dirname(__file__), "data",
                                 "testapp_0.1.2_all.deb")
        self.assertTrue(os.path.exists(dest_file))
        os.unlink(dest_file)

        # now set some prerm etc directly and check
        d = Deployment('testapp', base=basepath)
        d.root_path = os.path.join(basepath, '.parcel_test')
        lines = ['test line one', 'test line two']
        d.prerm = " ".join(lines)
        d.postrm = " ".join(lines)
        d.preinst = " ".join(lines)
        d.postinst = " ".join(lines)
        d.build_package()
        dest_file = os.path.join(os.path.dirname(__file__), "data",
                                 "testapp_0.1.2_all.deb")
        self.assertTrue(os.path.exists(dest_file))
        os.unlink(dest_file)
Exemple #16
0
    def test_deployment(self):
        basepath = os.path.join(os.path.expanduser('~/'))
        d = Deployment('testapp', base=basepath)
        d.prepare_app()

        # check that sync_app worked
        self.assertTrue(os.path.exists(d.build_path))

        # check that virtualenv was built
        ve_path = os.path.join(d.build_path, d.virtual)
        self.assertTrue(os.path.exists(ve_path))

        # check we can add a file
        test_file = os.path.join(os.path.dirname(__file__), "data",
                                 "tip.tar.gz")
        d.add_to_root_fs(test_file, 'tip.tar.gz')
        dest_file = os.path.join(d.root_path, "tip.tar.gz")
        self.assertTrue(os.path.exists(dest_file))

        # now check with a leading slash
        d.add_to_root_fs(test_file, '/tip.tar.gz')
        dest_file = os.path.join(d.root_path, "tip.tar.gz")
        self.assertTrue(os.path.exists(dest_file))

        # check we can add data
        data = "this is some test data"
        d.add_data_to_root_fs(data, "test_data.txt")
        dest_file = os.path.join(d.root_path, "test_data.txt")
        self.assertTrue(os.path.exists(dest_file))
        with open(dest_file) as f:
            self.assertEquals(data, f.read())

        # try the same with a leading slash
        data = "this is some test data"
        d.add_data_to_root_fs(data, "/test_data.txt")
        dest_file = os.path.join(d.root_path, "test_data.txt")
        self.assertTrue(os.path.exists(dest_file))
        with open(dest_file) as f:
            self.assertEquals(data, f.read())

        # check we can compile python files
        d.compile_python()
        dest_file = os.path.join(d.build_path, 'data', 'hello.pyc')
        self.assertTrue(os.path.exists(dest_file))

        # check we can clear .py and just leave .pyc files
        d.clear_py_files()
        dest_file = os.path.join(d.build_path, 'data', 'hello.py')
        self.assertFalse(os.path.exists(dest_file))