예제 #1
0
 def test_missing_environment(self):
     """
     If no cluster option and no environment, script fails
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     with capture_stderr() as captured_stderr:
         with self.assertRaises(SystemExit) as e:
             get_cluster(options, {})
         self.assertIn('not set', e.exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
예제 #2
0
 def test_environment_hostname_mapping_invalid_json(self):
     """
     Rejects configuration if hostname mapping is invalid.
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     self.environ['FLOCKER_ACCEPTANCE_HOSTNAME_TO_PUBLIC_ADDRESS'] = '}'
     with capture_stderr() as captured_stderr:
         with self.assertRaises(SystemExit) as e:
             get_cluster(options, self.environ)
         self.assertIn('JSON', e.exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
예제 #3
0
 def test_environment_invalid_control_node(self):
     """
     Rejects configuration if control node is invalid.
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     self.environ['FLOCKER_ACCEPTANCE_CONTROL_NODE'] = 'notanipaddress'
     with capture_stderr() as captured_stderr:
         with self.assertRaises(SystemExit) as e:
             get_cluster(options, self.environ)
         self.assertIn('notanipaddress', e.exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
예제 #4
0
    def test_missing_yaml_file(self):
        """
        Script fails if cluster directory does not contain cluster.yml

        There is no fallback to environment if an error occurs reading
        YAML description.
        """
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)
        options = BenchmarkOptions()
        options.parseOptions(['--cluster', tmpdir])
        with capture_stderr() as captured_stderr:
            with self.assertRaises(SystemExit) as e:
                get_cluster(options, self.environ)
            self.assertIn('not found', e.exception.args[0])
            self.assertIn(options.getUsage(), captured_stderr())
예제 #5
0
    def test_environment_setup_aws(self):
        """
        Uses environment variables for cluster configuration if option missing.

        This test checks a typical AWS configuration.
        """
        options = BenchmarkOptions()
        options.parseOptions([])
        cluster = get_cluster(options, self.environ)
        self.assertEqual(cluster.control_node_address(),
                         IPAddress(_ENV_CONTROL_SERVICE_ADDRESS))
예제 #6
0
    def test_environment_setup_aws(self):
        """
        Uses environment variables for cluster configuration if option missing.

        This test checks a typical AWS configuration.
        """
        options = BenchmarkOptions()
        options.parseOptions([])
        cluster = get_cluster(options, self.environ)
        self.assertEqual(
            cluster.control_node_address(),
            IPAddress(_ENV_CONTROL_SERVICE_ADDRESS)
        )
예제 #7
0
    def test_environment_setup_rackspace(self):
        """
        Uses environment variables for cluster configuration if option missing.

        This test checks a typical Rackspace configuration.
        """
        self.environ['FLOCKER_ACCEPTANCE_HOSTNAME_TO_PUBLIC_ADDRESS'] = '{}'
        self.environ['FLOCKER_ACCEPTANCE_VOLUME_BACKEND'] = 'openstack'
        options = BenchmarkOptions()
        options.parseOptions([])
        cluster = get_cluster(options, self.environ)
        self.assertEqual(cluster.control_node_address(),
                         IPAddress(_ENV_CONTROL_SERVICE_ADDRESS))
예제 #8
0
    def test_environment_setup_rackspace(self):
        """
        Uses environment variables for cluster configuration if option missing.

        This test checks a typical Rackspace configuration.
        """
        self.environ['FLOCKER_ACCEPTANCE_HOSTNAME_TO_PUBLIC_ADDRESS'] = '{}'
        self.environ['FLOCKER_ACCEPTANCE_VOLUME_BACKEND'] = 'openstack'
        options = BenchmarkOptions()
        options.parseOptions([])
        cluster = get_cluster(options, self.environ)
        self.assertEqual(
            cluster.control_node_address(),
            IPAddress(_ENV_CONTROL_SERVICE_ADDRESS)
        )
예제 #9
0
    def test_yaml_setup(self):
        """
        Uses YAML file for cluster configuration if option given.

        This is true even if the environment contains a valid configuration.
        """
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)
        with open(os.path.join(tmpdir, 'cluster.yml'), 'wt') as f:
            f.write(_CLUSTER_YAML_CONTENTS)
        options = BenchmarkOptions()
        options.parseOptions(['--cluster', tmpdir])
        cluster = get_cluster(options, self.environ)
        self.assertEqual(cluster.control_node_address(),
                         IPAddress(_YAML_CONTROL_SERVICE_ADDRESS))
예제 #10
0
    def test_yaml_setup(self):
        """
        Uses YAML file for cluster configuration if option given.

        This is true even if the environment contains a valid configuration.
        """
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)
        with open(os.path.join(tmpdir, 'cluster.yml'), 'wt') as f:
            f.write(_CLUSTER_YAML_CONTENTS)
        options = BenchmarkOptions()
        options.parseOptions(['--cluster', tmpdir])
        cluster = get_cluster(options, self.environ)
        self.assertEqual(
            cluster.control_node_address(),
            IPAddress(_YAML_CONTROL_SERVICE_ADDRESS)
        )