Пример #1
0
    def test_start_serving_bundle(self):
        """
        Test actually serving a deployed bundle, then taking it down.
        """
        self.install_my_bundle()
        (instance_id, node_name, host_ip, host_port) = \
            deploy.start_serving_bundle(self.app_id, self.bundle_name)

        self.assertTrue(isinstance(instance_id, str))
        self.assertTrue(isinstance(node_name, str))
        self.assertTrue(isinstance(host_ip, str))
        self.assertTrue(isinstance(host_port, int))

        app_url = "http://%s:%d" % (host_ip, host_port)

        self.check_can_eventually_load(
            app_url,
            "Welcome to the Django tutorial polls app")

        # we shouldn't be able to serve the same bundle again from this
        # appserver
        with self.assertRaises(utils.InfrastructureException):
            deploy.start_serving_bundle(self.app_id, self.bundle_name)

        num_stopped = deploy.stop_serving_bundle(self.app_id, self.bundle_name)

        self.assertEqual(num_stopped, 1)

        with self.assertRaises(IOError):
            urllib.urlopen(app_url).read()
Пример #2
0
    def test_safe_deploy(self):
        """
        Test that deployed code runs under the proper user.
        """
        self.install_my_bundle()
        (instance_id, node_name, host_ip, host_port) = \
            deploy.start_serving_bundle(self.app_id, self.bundle_name)
        app_url = "http://%s:%d/securitytest/" % (host_ip, host_port)
        security_result = self.check_can_eventually_load(
            app_url)
        self.assertTrue(security_result.startswith("SECURITY TEST RESULTS"))

        # convert security lines into a dict
        # EXAMPLE (a failing result):
        """SECURITY TEST RESULTS
whoami: shimon
ls /: bin,boot,cdrom,cgroup,cust,dev,etc,home,initrd.img,initrd.img.old,lib,lib32,lib64,lost+found,media,mnt,opt,proc,root,sbin,selinux,srv,sys,tmp,usr,var,vmlinuz,vmlinuz.old
        """

        sec = {}
        for line in security_result.splitlines()[1:]:
            line = line.strip()
            if not ": " in line:
                continue
            k, v = line.split(": ", 1)
            sec[k] = v

        self.assertEqual(sec["whoami"], self.app_id,
                         ("Expected app to be running as %r, but actually "
                          "is running as %r") % (self.app_id, sec["whoami"]))
        self.assertEqual(sec["ls /"], ",".join(
            sorted(['bin', 'dev', 'etc', 'lib', 'lib64', 'usr',
                    taskconfig.NR_CUSTOMER_DIR.strip("/").split("/")[0]])))
Пример #3
0
    def test_undeploy_by_dep_ids(self):
        """
        Test taking down a deployed bundle based on the appserverdeployment id.
        """
        app_dir, bundle_dir = utils.app_and_bundle_dirs(self.app_id,
                                                        self.bundle_name)
        self.install_my_bundle()
        (instance_id, node_name, host_ip, host_port) = \
            deploy.start_serving_bundle(self.app_id, self.bundle_name)

        self.assertTrue(os.path.isdir(bundle_dir))

        self.check_can_eventually_load(
            "http://%s:%s" % (host_ip, host_port),
            "Welcome to the Django tutorial polls app")

        zoomdb = StubZoomDB()
        mydep = zoomdb.add_worker(1, "localhost", "127.0.0.1", host_port)

        self.assertFalse(deploy.is_port_open(host_port))

        deploy.undeploy(zoomdb,
                        self.app_id,
                        dep_ids=[mydep.id],
                        use_subtasks=False,
                        also_update_proxies=False)

        self.assertTrue(deploy.is_port_open(host_port))
        #self.assertFalse(os.path.isdir(app_dir))
        self.assertFalse(os.path.isdir(bundle_dir))
Пример #4
0
    def test_undeploy_with_proxy_update(self):
        """
        Test taking down a deployed bundle and updating the proxy config too.
        """
        app_dir, bundle_dir = utils.app_and_bundle_dirs(self.app_id,
                                                        self.bundle_name)
        self.install_my_bundle()
        (instance_id, node_name, host_ip, host_port) = \
            deploy.start_serving_bundle(self.app_id, self.bundle_name)

        # also add to nginx - fake it for this test
        here = os.path.abspath(os.path.split(__file__)[0])
        fixture_dir = os.path.join(here, '../fixtures')
        nginx_site_file = os.path.join(taskconfig.NGINX_SITES_ENABLED_DIR,
                                       self.app_id)
        shutil.copyfile(os.path.join(fixture_dir, 'test_deploy_nginx_site'),
                        nginx_site_file)

        self.check_can_eventually_load(
            "http://%s:%s" % (host_ip, host_port),
            "Welcome to the Django tutorial polls app")

        zoomdb = StubZoomDB()
        mydep = zoomdb.add_worker(1, "localhost", "127.0.0.1", host_port)

        self.assertFalse(deploy.is_port_open(host_port))

        zcfg_path = os.path.join(fixture_dir, "app", "zoombuild.cfg")
        zcfg_content = open(zcfg_path).read()

        # make sure we require proper parameters - skip zoombuild_cfg_content
        with self.assertRaises(AssertionError):
            deploy.undeploy(zoomdb,
                            self.app_id,
                            dep_ids=[mydep.id],
                            use_subtasks=False,
                            also_update_proxies=True)

        deploy.undeploy(zoomdb,
                        self.app_id,
                        dep_ids=[mydep.id],
                        use_subtasks=False,
                        also_update_proxies=True,
                        zoombuild_cfg_content=zcfg_content)

        self.assertTrue(deploy.is_port_open(host_port))
        self.assertFalse(os.path.isdir(bundle_dir))
        self.assertFalse(os.path.isfile(nginx_site_file),
                         "Expected nginx site file %s to be gone, but it isn't"
                         % nginx_site_file)