Esempio n. 1
0
    def test_undeploy(self):
        """
        Test taking down a deployed bundle.
        """
        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()
        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,
                        None,  # or [1],
                        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))
Esempio n. 2
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)
Esempio n. 3
0
    def test_update_hostnames(self):
        """
        Test the update_hostnames task.
        """

        zoomdb = StubZoomDB()
        test_fixture_cfg = self.get_fixture_path("app", "zoombuild.cfg")
        zoombuild_cfg_content = file(test_fixture_cfg).read()

        expected_site_file = os.path.join(taskconfig.NGINX_SITES_ENABLED_DIR, self.app_id)

        self.assertFalse(os.path.isfile(expected_site_file))

        # first test that when we have no deployments, nothing happens.
        nginx.update_hostnames(zoomdb, self.app_id, zoombuild_cfg_content, use_subtasks=False)

        self.assertTrue(any("has not yet been deployed" in x[0] for x in zoomdb.logs))
        self.assertFalse(os.path.isfile(expected_site_file))

        # but that's certainly not the goal when we DO have deployments.
        zoomdb = StubZoomDB()
        zoomdb.add_worker(1, 1, "1.2.3.4", 12345)

        # and add a vhost
        zoomdb.test_vhosts = ["mycompany.com", "www.mycompany.com"]
        nginx.update_hostnames(zoomdb, self.app_id, zoombuild_cfg_content, use_subtasks=False)

        self.assertFalse(any("has not yet been deployed" in x[0] for x in zoomdb.logs))
        self.assertTrue(any("project will be accessible via" in x[0] for x in zoomdb.logs))

        self.assertTrue(os.path.isfile(expected_site_file))
        file_content = file(expected_site_file).read()
        linesplit_contents = [" ".join(x.strip().split()) for x in file_content.split("\n")]

        vhost_line = "server_name test-p00000001.djangozoom.net %s ;" % (" ".join(zoomdb.test_vhosts))

        self.assertTrue(vhost_line in linesplit_contents)