Example #1
0
def update_proxy_conf(job_id, zoomdb, app_id, bundle_name,
                      appservers, virtual_hostnames, site_media_map,
                      remove_other_bundles=True):
    nginx.update_local_proxy_config(
        app_id, bundle_name,
        appservers, virtual_hostnames, site_media_map,
        remove_other_bundles=remove_other_bundles)
Example #2
0
    def test_creating_new(self):
        """
        Test creating a new nginx config file for an app.
        """
        expected_site_file = os.path.join(taskconfig.NGINX_SITES_ENABLED_DIR, self.app_id)
        self.assertFalse(os.path.isfile(expected_site_file))

        self._mock_local_privileged()

        self.assertEqual(len(self.local_privileged_cmds), 0)

        nginx.update_local_proxy_config(
            self.app_id,
            self.bundle_name,
            self.appservers,
            self.virtual_hostnames,
            self.site_media_map,
            bundle_storage_engine=nginx.SKIP_BUNDLE_INSTALL,
        )

        self.assertEqual(len(self.local_privileged_cmds), 1)
        self.assertEqual(self.local_privileged_cmds[0], ["kick_nginx"])

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

        file_content = file(expected_site_file).read()

        self.assertTrue(len(file_content) > 0, "doh, conf file appears empty")

        for (instance_id, node_name, host_ip, host_port) in self.appservers:
            upstream_line = "server %s:%d" % (host_ip, host_port)
            self.assertTrue(upstream_line in file_content)
Example #3
0
    def test_remove_proxy_config(self):
        """
        Test removing proxy service for an app.
        """
        self._mock_local_privileged()

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

        # first try remove before it's created; that should crash
        self.assertFalse(os.path.isfile(expected_site_file))
        with self.assertRaises(utils.InfrastructureException):
            nginx.remove_local_proxy_config(self.app_id)

        # now create
        nginx.update_local_proxy_config(
            self.app_id,
            self.bundle_name,
            self.appservers,
            self.virtual_hostnames,
            self.site_media_map,
            bundle_storage_engine=nginx.SKIP_BUNDLE_INSTALL,
        )
        self.assertTrue(os.path.isfile(expected_site_file))

        self.assertEqual(len(self.local_privileged_cmds), 1)
        self.assertEqual(self.local_privileged_cmds[0], ["kick_nginx"])

        # now remove for real
        nginx.remove_local_proxy_config(self.app_id)
        self.assertFalse(os.path.isfile(expected_site_file))

        self.assertEqual(len(self.local_privileged_cmds), 2)
        self.assertEqual(self.local_privileged_cmds[1], ["kick_nginx"])
Example #4
0
 def test_fail_when_no_appservers(self):
     """
     Test that >0 appservers must be provided.
     """
     with self.assertRaises(utils.InfrastructureException):
         nginx.update_local_proxy_config(
             self.app_id, self.bundle_name, [], self.virtual_hostnames, self.site_media_map  # no appservers
         )
Example #5
0
    def _do_update_and_get_site_conf_contents(self):
        expected_site_file = os.path.join(taskconfig.NGINX_SITES_ENABLED_DIR, self.app_id)

        nginx.update_local_proxy_config(
            self.app_id,
            self.bundle_name,
            self.appservers,
            self.virtual_hostnames,
            self.site_media_map,
            bundle_storage_engine=nginx.SKIP_BUNDLE_INSTALL,
        )

        return file(expected_site_file).read()
Example #6
0
    def test_downloads_bundle_when_new(self):
        """
        Test that serving a bundle downloads it (so static media are on
        disk).
        """
        # first just make the bundle and ensure it's in local storage
        cust_dir = self.makeDir()
        self.patch(taskconfig, "NR_CUSTOMER_DIR", cust_dir)

        bundle_name = "bundle_test_deploy_app_2011-fixture"
        app_id = "test_deploy_app"
        bundle_in_storage = os.path.join(taskconfig.NR_CUSTOMER_DIR, "bundle_storage_local", bundle_name + ".tgz")

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

        from test_deploy import create_test_bundle_in_local_storage

        bundle_tgz_name = create_test_bundle_in_local_storage()

        self.assertTrue(os.path.isfile(bundle_in_storage))
        self.assertTrue(bundle_in_storage.endswith(bundle_tgz_name))

        bundle_dir = os.path.join(cust_dir, app_id, bundle_name)

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

        # ok, now serve it
        nginx.update_local_proxy_config(
            app_id,
            bundle_name,
            self.appservers,
            self.virtual_hostnames,
            self.site_media_map,
            bundle_storage_engine=bundle_storage_local,
        )

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