Beispiel #1
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)
Beispiel #2
0
def update_hostnames(job_id, zoomdb, job_params):
    nginx.update_hostnames(zoomdb, job_params["app_id"],
                           job_params["zoombuild_cfg_content"])