Exemplo n.º 1
0
 def test_all_utf8_encoded(self, m_load_file):
     """common path where only utf-8 decodable content."""
     content = self.null.join((self.simple1, self.simple2))
     m_load_file.return_value = content
     self.assertEqual(
         {'HOME': '/', 'PATH': '/bin:/sbin'},
         util.get_proc_env(1))
     self.assertEqual(1, m_load_file.call_count)
Exemplo n.º 2
0
 def test_all_utf8_encoded(self, m_load_file):
     """common path where only utf-8 decodable content."""
     content = self.null.join((self.simple1, self.simple2))
     m_load_file.return_value = content
     self.assertEqual(
         {'HOME': '/', 'PATH': '/bin:/sbin'},
         util.get_proc_env(1))
     self.assertEqual(1, m_load_file.call_count)
Exemplo n.º 3
0
    def test_encoding_none_returns_bytes(self, m_load_file):
        """encoding none returns bytes."""
        lines = (self.bootflag, self.simple1, self.simple2, self.mixed)
        content = self.null.join(lines)
        m_load_file.return_value = content

        self.assertEqual(dict([t.split(b'=') for t in lines]),
                         util.get_proc_env(1, encoding=None))
        self.assertEqual(1, m_load_file.call_count)
Exemplo n.º 4
0
    def test_encoding_none_returns_bytes(self, m_load_file):
        """encoding none returns bytes."""
        lines = (self.bootflag, self.simple1, self.simple2, self.mixed)
        content = self.null.join(lines)
        m_load_file.return_value = content

        self.assertEqual(
            dict([t.split(b'=') for t in lines]),
            util.get_proc_env(1, encoding=None))
        self.assertEqual(1, m_load_file.call_count)
Exemplo n.º 5
0
    def test_non_utf8_in_environment(self, m_load_file):
        """env may have non utf-8 decodable content."""
        content = self.null.join(
            (self.bootflag, self.simple1, self.simple2, self.mixed))
        m_load_file.return_value = content

        self.assertEqual(
            {'BOOTABLE_FLAG': self._val_decoded(self.bootflag),
             'HOME': '/', 'PATH': '/bin:/sbin',
             'MIXED': self._val_decoded(self.mixed)},
            util.get_proc_env(1))
        self.assertEqual(1, m_load_file.call_count)
Exemplo n.º 6
0
    def test_non_utf8_in_environment(self, m_load_file):
        """env may have non utf-8 decodable content."""
        content = self.null.join(
            (self.bootflag, self.simple1, self.simple2, self.mixed))
        m_load_file.return_value = content

        self.assertEqual(
            {'BOOTABLE_FLAG': self._val_decoded(self.bootflag),
             'HOME': '/', 'PATH': '/bin:/sbin',
             'MIXED': self._val_decoded(self.mixed)},
            util.get_proc_env(1))
        self.assertEqual(1, m_load_file.call_count)
Exemplo n.º 7
0
def detect_openstack():
    """Return True when a potential OpenStack platform is detected."""
    if not util.is_x86():
        return True  # Non-Intel cpus don't properly report dmi product names
    product_name = util.read_dmi_data('system-product-name')
    if product_name in VALID_DMI_PRODUCT_NAMES:
        return True
    elif util.read_dmi_data('chassis-asset-tag') in VALID_DMI_ASSET_TAGS:
        return True
    elif util.get_proc_env(1).get('product_name') == DMI_PRODUCT_NOVA:
        return True
    return False
Exemplo n.º 8
0
def detect_openstack(accept_oracle=False):
    """Return True when a potential OpenStack platform is detected."""
    if not util.is_x86():
        return True  # Non-Intel cpus don't properly report dmi product names
    product_name = util.read_dmi_data('system-product-name')
    if product_name in VALID_DMI_PRODUCT_NAMES:
        return True
    elif util.read_dmi_data('chassis-asset-tag') in VALID_DMI_ASSET_TAGS:
        return True
    elif accept_oracle and oracle._is_platform_viable():
        return True
    elif util.get_proc_env(1).get('product_name') == DMI_PRODUCT_NOVA:
        return True
    return False
Exemplo n.º 9
0
def detect_openstack(accept_oracle=False):
    """Return True when a potential OpenStack platform is detected."""
    if not util.is_x86():
        return True  # Non-Intel cpus don't properly report dmi product names
    product_name = dmi.read_dmi_data("system-product-name")
    if product_name in VALID_DMI_PRODUCT_NAMES:
        return True
    elif dmi.read_dmi_data("chassis-asset-tag") in VALID_DMI_ASSET_TAGS:
        return True
    elif accept_oracle and oracle._is_platform_viable():
        return True
    elif util.get_proc_env(1).get("product_name") == DMI_PRODUCT_NOVA:
        return True
    return False
Exemplo n.º 10
0
 def test_non_existing_file_returns_empty_dict(self, m_load_file):
     """as implemented, a non-existing pid returns empty dict.
     This is how it was originally implemented."""
     m_load_file.side_effect = OSError("File does not exist.")
     self.assertEqual({}, util.get_proc_env(1))
     self.assertEqual(1, m_load_file.call_count)
Exemplo n.º 11
0
 def test_non_existing_file_returns_empty_dict(self, m_load_file):
     """as implemented, a non-existing pid returns empty dict.
     This is how it was originally implemented."""
     m_load_file.side_effect = OSError("File does not exist.")
     self.assertEqual({}, util.get_proc_env(1))
     self.assertEqual(1, m_load_file.call_count)