Exemple #1
0
 def test_json_userdata(self):
     """
     JSON string adds to result.
     """
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '{"branch": "master"}'])
     self.assertEqual(parse_userdata(options), {"branch": "master"})
Exemple #2
0
 def test_no_userdata(self):
     """
     Missing option adds nothing to result.
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     self.assertIs(parse_userdata(options), None)
Exemple #3
0
 def test_empty_userdata(self):
     """
     Empty option adds nothing to result.
     """
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', ''])
     self.assertIs(parse_userdata(options), None)
Exemple #4
0
 def test_no_userdata(self):
     """
     Missing option adds nothing to result.
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     self.assertIs(parse_userdata(options), None)
Exemple #5
0
 def test_json_userdata(self):
     """
     JSON string adds to result.
     """
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '{"branch": "master"}'])
     self.assertEqual(parse_userdata(options), {"branch": "master"})
Exemple #6
0
 def test_empty_userdata(self):
     """
     Empty option adds nothing to result.
     """
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', ''])
     self.assertIs(parse_userdata(options), None)
Exemple #7
0
 def test_invalid_json(self):
     """
     Invalid JSON string handled.
     """
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '"branch": "master"'])
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(SystemExit, parse_userdata, options)
         self.assertIn('Invalid user data', exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #8
0
 def test_json_file_userdata(self):
     """
     JSON file adds to result.
     """
     json_file = FilePath(self.mktemp())
     with json_file.open('w') as f:
         f.write('{"branch": "master"}\n')
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '@{}'.format(json_file.path)])
     self.assertEqual(parse_userdata(options), {"branch": "master"})
Exemple #9
0
 def test_json_file_userdata(self):
     """
     JSON file adds to result.
     """
     json_file = FilePath(self.mktemp())
     with json_file.open('w') as f:
         f.write('{"branch": "master"}\n')
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '@{}'.format(json_file.path)])
     self.assertEqual(parse_userdata(options), {"branch": "master"})
Exemple #10
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))
Exemple #11
0
 def test_invalid_path(self):
     """
     Non-existent file handled.
     """
     no_file = FilePath(self.mktemp())
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '@{}'.format(no_file.path)])
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(SystemExit, parse_userdata, options)
         self.assertIn('Invalid user data file', exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #12
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())
Exemple #13
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())
Exemple #14
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())
Exemple #15
0
 def test_invalid_file_data(self):
     """
     Invalid file data handled.
     """
     invalid_file = FilePath(self.mktemp())
     with invalid_file.open('w') as f:
         f.write('hello\n')
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '@{}'.format(invalid_file.path)])
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(SystemExit, parse_userdata, options)
         self.assertIn('Invalid user data', exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #16
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)
        )
Exemple #17
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))
Exemple #18
0
 def test_invalid_json(self):
     """
     Invalid JSON string handled.
     """
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '"branch": "master"'])
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(
             SystemExit, parse_userdata, options
         )
         self.assertIn(
             'Invalid user data', exception.args[0]
         )
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #19
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)
        )
Exemple #20
0
 def test_invalid_path(self):
     """
     Non-existent file handled.
     """
     no_file = FilePath(self.mktemp())
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '@{}'.format(no_file.path)])
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(
             SystemExit, parse_userdata, options
         )
         self.assertIn(
             'Invalid user data file', exception.args[0]
         )
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #21
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:
         exception = self.assertRaises(
             SystemExit,
             get_cluster,
             options,
             {},
         )
         self.assertIn('not set', exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #22
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))
Exemple #23
0
 def test_environment_invalid_volume_size(self):
     """
     Rejects configuration if volume size is invalid.
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     self.environ['FLOCKER_ACCEPTANCE_DEFAULT_VOLUME_SIZE'] = 'A'
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(
             SystemExit,
             get_cluster, options, self.environ,
         )
         self.assertIn(
             'FLOCKER_ACCEPTANCE_DEFAULT_VOLUME_SIZE', exception.args[0]
         )
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #24
0
 def test_environment_hostname_mapping_invalid_ipaddress(self):
     """
     Rejects configuration if hostname mapping is invalid.
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     self.environ['FLOCKER_ACCEPTANCE_HOSTNAME_TO_PUBLIC_ADDRESS'] = (
         '{"notanipaddress": "notanipaddress"}'
     )
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(
             SystemExit,
             get_cluster, options, self.environ,
         )
         self.assertIn('notanipaddress', exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #25
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:
         exception = self.assertRaises(
             SystemExit,
             get_cluster,
             options,
             self.environ,
         )
         self.assertIn('notanipaddress', exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #26
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:
         exception = self.assertRaises(
             SystemExit,
             get_cluster,
             options,
             self.environ,
         )
         self.assertIn('JSON', exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #27
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())
Exemple #28
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)
        )
Exemple #29
0
 def test_invalid_file_data(self):
     """
     Invalid file data handled.
     """
     invalid_file = FilePath(self.mktemp())
     with invalid_file.open('w') as f:
         f.write('hello\n')
     options = BenchmarkOptions()
     options.parseOptions(['--userdata', '@{}'.format(invalid_file.path)])
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(
             SystemExit, parse_userdata, options
         )
         self.assertIn(
             'Invalid user data', exception.args[0]
         )
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #30
0
 def test_environment_invalid_volume_size(self):
     """
     Rejects configuration if volume size is invalid.
     """
     options = BenchmarkOptions()
     options.parseOptions([])
     self.environ['FLOCKER_ACCEPTANCE_DEFAULT_VOLUME_SIZE'] = 'A'
     with capture_stderr() as captured_stderr:
         exception = self.assertRaises(
             SystemExit,
             get_cluster,
             options,
             self.environ,
         )
         self.assertIn('FLOCKER_ACCEPTANCE_DEFAULT_VOLUME_SIZE',
                       exception.args[0])
         self.assertIn(options.getUsage(), captured_stderr())
Exemple #31
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:
            exception = self.assertRaises(
                SystemExit,
                get_cluster,
                options,
                self.environ,
            )
            self.assertIn('not found', exception.args[0])
            self.assertIn(options.getUsage(), captured_stderr())