Exemplo n.º 1
0
 def test_parse_key_value_additional_eparator(self):
     contents = """
         key1: value1:value11
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual({"key1": "value1:value11"},
                      parse_key_value_file(file_name))
Exemplo n.º 2
0
def run_repeated_keygen(tmpdir):
    # omshell has a bug where if the chars '/' or '+' appear either
    # side of the word 'no' (in any case), it throws an error like
    # "partial base64 value left over".  We check for that here and
    # repeatedly generate a new key until a good one is generated.

    key = None
    while key is None:
        key_id = call_dnssec_keygen(tmpdir)

        # Locate the file that was written and strip out the Key: field in
        # it.
        if not key_id:
            raise AssertionError("dnssec-keygen didn't generate anything")
        key_id = key_id.decode("ascii").strip()  # Remove trailing newline.
        key_file_name = os.path.join(tmpdir, key_id + ".private")
        parsing_error = False
        try:
            config = parse_key_value_file(key_file_name)
        except ValueError:
            parsing_error = True
        if parsing_error or "Key" not in config:
            raise AssertionError(
                "Key field not found in output from dnssec-keygen"
            )

        key = config["Key"]
        if bad_key_pattern.search(key) is not None:
            # Force a retry.
            os.remove(key_file_name)  # Stop dnssec_keygen complaints.
            key = None

    return key
Exemplo n.º 3
0
    def test_parse_key_value_copes_with_empty_lines(self):
        contents = """
            key1: value1

            """
        file_name = self.make_file(contents=contents)
        self.assertEqual({"key1": "value1"}, parse_key_value_file(file_name))
Exemplo n.º 4
0
 def test_parse_key_value_additional_eparator(self):
     contents = """
         key1: value1:value11
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual(
         {'key1': 'value1:value11'}, parse_key_value_file(file_name))
Exemplo n.º 5
0
def run_repeated_keygen(tmpdir):
    # omshell has a bug where if the chars '/' or '+' appear either
    # side of the word 'no' (in any case), it throws an error like
    # "partial base64 value left over".  We check for that here and
    # repeatedly generate a new key until a good one is generated.

    key = None
    while key is None:
        key_id = call_dnssec_keygen(tmpdir)

        # Locate the file that was written and strip out the Key: field in
        # it.
        if not key_id:
            raise AssertionError("dnssec-keygen didn't generate anything")
        key_id = key_id.strip()  # Remove trailing newline.
        key_file_name = os.path.join(tmpdir, key_id + '.private')
        parsing_error = False
        try:
            config = parse_key_value_file(key_file_name)
        except ValueError:
            parsing_error = True
        if parsing_error or 'Key' not in config:
            raise AssertionError(
                "Key field not found in output from dnssec-keygen")

        key = config['Key']
        if bad_key_pattern.search(key) is not None:
            # Force a retry.
            os.remove(key_file_name)  # Stop dnssec_keygen complaints.
            key = None

    return key
Exemplo n.º 6
0
    def test_parse_key_value_copes_with_empty_lines(self):
        contents = """
            key1: value1

            """
        file_name = self.make_file(contents=contents)
        self.assertEqual(
            {'key1': 'value1'}, parse_key_value_file(file_name))
Exemplo n.º 7
0
 def test_parse_key_value_file_parse_alternate_separator(self):
     contents = """
         key1= value1
         key2   =  value2
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual(
         {'key1': 'value1', 'key2': 'value2'},
         parse_key_value_file(file_name, separator='='))
Exemplo n.º 8
0
 def test_parse_key_value_file_parse_alternate_separator(self):
     contents = """
         key1= value1
         key2   =  value2
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual(
         {'key1': 'value1', 'key2': 'value2'},
         parse_key_value_file(file_name, separator='='))
Exemplo n.º 9
0
 def test_parse_key_value_file_parses_config_file(self):
     contents = """
         key1: value1
         key2  :  value2
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual(
         {'key1': 'value1', 'key2': 'value2'},
         parse_key_value_file(file_name))
Exemplo n.º 10
0
 def test_parse_key_value_file_parses_config_file(self):
     contents = """
         key1: value1
         key2  :  value2
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual(
         {'key1': 'value1', 'key2': 'value2'},
         parse_key_value_file(file_name))
Exemplo n.º 11
0
 def test_parse_key_value_file_parse_alternate_separator(self):
     contents = """
         key1= value1
         key2   =  value2
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual(
         {"key1": "value1", "key2": "value2"},
         parse_key_value_file(file_name, separator="="),
     )
Exemplo n.º 12
0
 def test_parse_key_value_file_parses_config_file(self):
     contents = """
         key1: value1
         key2  :  value2
         """
     file_name = self.make_file(contents=contents)
     self.assertEqual(
         {"key1": "value1", "key2": "value2"},
         parse_key_value_file(file_name),
     )
Exemplo n.º 13
0
def get_ephemeral_name(release, arch):
    """Return the name of the most recent ephemeral image.

    That information is read from the config file named 'info' in the
    ephemeral directory e.g:
    /var/lib/maas/ephemeral/precise/ephemeral/i386/20120424/info
    """
    config = Config.load_from_cache()
    root = os.path.join(config["boot"]["ephemeral"]["images_directory"],
                        release, 'ephemeral', arch)
    try:
        filename = os.path.join(get_last_directory(root), 'info')
    except OSError:
        raise EphemeralImagesDirectoryNotFound(
            "The directory containing the ephemeral images/info is missing "
            "(%r).  Make sure to run the script "
            "'maas-import-pxe-files'." % root)
    name = parse_key_value_file(filename, separator="=")['name']
    return name
Exemplo n.º 14
0
def get_ephemeral_name(release, arch):
    """Return the name of the most recent ephemeral image.

    That information is read from the config file named 'info' in the
    ephemeral directory e.g:
    /var/lib/maas/ephemeral/precise/ephemeral/i386/20120424/info
    """
    config = Config.load_from_cache()
    root = os.path.join(
        config["boot"]["ephemeral"]["images_directory"],
        release, 'ephemeral', arch)
    try:
        filename = os.path.join(get_last_directory(root), 'info')
    except OSError:
        raise EphemeralImagesDirectoryNotFound(
            "The directory containing the ephemeral images/info is missing "
            "(%r).  Make sure to run the script "
            "'maas-import-pxe-files'." % root)
    name = parse_key_value_file(filename, separator="=")['name']
    return name