Esempio n. 1
0
    def setUp(self):
        # create a temp file for use as a config file. This should get cleaned
        # up magically at the end of the run.
        self.fid = NamedTemporaryFile(mode='w+b', suffix='.tmp')
        self.fid.write(TEST_CONFIG)
        self.fid.seek(0)

        self.cfgParser = RhsmConfigParser(self.fid.name)
Esempio n. 2
0
    def test_auto_persist(self):
        config = Config(self.parser, auto_persist=True)
        self.assertEqual('baz', config['foo']['quux'])
        config['foo']['quux'] = 'fizz'
        self.assertEqual('fizz', config['foo']['quux'])

        reparsed = RhsmConfigParser(self.fid.name)
        self.assertEqual('fizz', reparsed.get('foo', 'quux'))
    def test_auto_persist(self):
        config = Config(self.parser, auto_persist=True)
        self.assertEqual('baz', config['foo']['quux'])
        config['foo']['quux'] = 'fizz'
        self.assertEqual('fizz', config['foo']['quux'])

        reparsed = RhsmConfigParser(self.fid.name)
        self.assertEqual('fizz', reparsed.get('foo', 'quux'))
    def test_auto_persist(self):
        config = Config(self.parser, auto_persist=True)
        self.assertEqual("baz", config["foo"]["quux"])
        config["foo"]["quux"] = "fizz"
        self.assertEqual("fizz", config["foo"]["quux"])

        reparsed = RhsmConfigParser(self.fid.name)
        self.assertEqual("fizz", reparsed.get("foo", "quux"))
    def test_persist_cascades(self):
        config = Config(self.parser, auto_persist=False)
        self.assertEqual('baz', config['foo']['quux'])
        config['foo']['quux'] = 'fizz'
        config.persist()
        self.assertEqual('fizz', config['foo']['quux'])

        reparsed = RhsmConfigParser(self.fid.name)
        self.assertEqual('fizz', reparsed.get('foo', 'quux'))
Esempio n. 6
0
    def test_persist_cascades(self):
        config = Config(self.parser, auto_persist=False)
        self.assertEqual('baz', config['foo']['quux'])
        config['foo']['quux'] = 'fizz'
        config.persist()
        self.assertEqual('fizz', config['foo']['quux'])

        reparsed = RhsmConfigParser(self.fid.name)
        self.assertEqual('fizz', reparsed.get('foo', 'quux'))
    def test_persist_cascades(self):
        config = Config(self.parser, auto_persist=False)
        self.assertEqual("baz", config["foo"]["quux"])
        config["foo"]["quux"] = "fizz"
        config.persist()
        self.assertEqual("fizz", config["foo"]["quux"])

        reparsed = RhsmConfigParser(self.fid.name)
        self.assertEqual("fizz", reparsed.get("foo", "quux"))
Esempio n. 8
0
def upload_tracer_profile(conduit=False):
    data = json.dumps({"traces": get_apps(conduit)})
    headers = {"Content-type": "application/json"}

    conn = httplib.HTTPSConnection(
        RhsmConfigParser.get(initConfig(), "server", "hostname"),
        RhsmConfigParser.get(initConfig(), "server", "port"),
        key_file=ConsumerIdentity.keypath(),
        cert_file=ConsumerIdentity.certpath(),
    )
    conn.request("PUT", "/rhsm/consumers/%s/tracer" % (ConsumerIdentity.read().getConsumerId()), data, headers=headers)
    response = conn.getresponse()
def upload_tracer_profile(conduit=False):
    data =  json.dumps({ "traces": get_apps(conduit) })
    headers = { "Content-type": "application/json" }

    conn = httplib.HTTPSConnection(
            RhsmConfigParser.get(initConfig() ,'server', 'hostname'),
            RhsmConfigParser.get(initConfig() ,'server', 'port'),
            key_file = ConsumerIdentity.keypath(),
            cert_file = ConsumerIdentity.certpath()
           )
    conn.request('PUT', '/rhsm/consumers/%s/tracer' % (ConsumerIdentity.read().getConsumerId()), data, headers=headers)
    response = conn.getresponse()
Esempio n. 10
0
class ConfigTests(unittest.TestCase):
    def setUp(self):
        # create a temp file for use as a config file. This should get cleaned
        # up magically at the end of the run.
        self.fid = NamedTemporaryFile(mode='w+b', suffix='.tmp')
        self.fid.write(TEST_CONFIG)
        self.fid.seek(0)

        self.cfgParser = RhsmConfigParser(self.fid.name)

    def testRead(self):
        self.assertEquals(self.cfgParser.get('server', 'hostname'),
                          'server.example.conf')

    def testSet(self):
        self.cfgParser.set('rhsm', 'baseurl', 'cod')
        self.assertEquals(self.cfgParser.get('rhsm', 'baseurl'), 'cod')

    def test_get(self):
        value = self.cfgParser.get("rhsm", "baseurl")
        self.assertEquals("https://content.example.com", value)

    def test_get_empty(self):
        value = self.cfgParser.get("foo", "bar")
        self.assertEquals("", value)

    def test_get_int(self):
        value = self.cfgParser.get_int("server", "port")
        self.assertTrue(isinstance(value, types.IntType))
        self.assertEquals(8443, value)

    def test_get_item_does_not_exist(self):
        self.assertRaises(NoOptionError, self.cfgParser.get, "rhsm",
                          "this_isnt_a_thing")

    def test_get_int_un_set(self):
        value = self.cfgParser.get_int("server", "proxy_port")
        self.assertEquals(None, value)

    def test_get_int_does_not_exist(self):
        self.assertRaises(NoOptionError, self.cfgParser.get_int, "rhsm",
                          "this_isnt_a_thing")

    def test_get_int_not_an_int(self):
        self.assertRaises(ValueError, self.cfgParser.get_int, "rhsm",
                          "baseurl")

    def test_get_int_big_int(self):
        value = self.cfgParser.get_int("foo", "bigger_than_32_bit")
        self.assertEquals(21474836470, value)
        value = self.cfgParser.get_int("foo", "bigger_than_64_bit")
        self.assertEquals(123456789009876543211234567890, value)
Esempio n. 11
0
def getRHSMUuid():
    """ Tries to get UUID of of this system if it's registered into Subscription manager."""

    if RhsmConfigParser and os.path.isfile(DEFAULT_RHSM_CONFIG_FILE):
        cfg = RhsmConfigParser(config_file=DEFAULT_RHSM_CONFIG_FILE)
        cert_dir = cfg.get('rhsm', 'consumerCertDir')
        cert_path = os.path.join(cert_dir, 'cert.pem')
        if os.path.isfile(cert_path):
            f = open(cert_path, 'r')
            cert = X509.load_cert_string(f.read())
            f.close()
            subject = cert.get_subject()
            return subject.CN
    return None
Esempio n. 12
0
def getRHSMUuid():
    """ Tries to get UUID of of this system if it's registered into Subscription manager."""

    if RhsmConfigParser and os.path.isfile(DEFAULT_RHSM_CONFIG_FILE):
        cfg = RhsmConfigParser(config_file=DEFAULT_RHSM_CONFIG_FILE)
        cert_dir = cfg.get('rhsm', 'consumerCertDir')
        cert_path = os.path.join(cert_dir, 'cert.pem')
        if os.path.isfile(cert_path):
            f = open(cert_path, 'r')
            cert = X509.load_cert_string(f.read())
            f.close()
            subject = cert.get_subject()
            return subject.CN
    return None
Esempio n. 13
0
class ConfigTests(unittest.TestCase):
    def setUp(self):
        # create a temp file for use as a config file. This should get cleaned
        # up magically at the end of the run.
        self.fid = NamedTemporaryFile(mode="w+b", suffix=".tmp")
        self.fid.write(TEST_CONFIG)
        self.fid.seek(0)

        self.cfgParser = RhsmConfigParser(self.fid.name)

    def testRead(self):
        self.assertEquals(self.cfgParser.get("server", "hostname"), "server.example.conf")

    def testSet(self):
        self.cfgParser.set("rhsm", "baseurl", "cod")
        self.assertEquals(self.cfgParser.get("rhsm", "baseurl"), "cod")

    def test_get(self):
        value = self.cfgParser.get("rhsm", "baseurl")
        self.assertEquals("https://content.example.com", value)

    def test_get_empty(self):
        value = self.cfgParser.get("foo", "bar")
        self.assertEquals("", value)

    def test_get_int(self):
        value = self.cfgParser.get_int("server", "port")
        self.assertTrue(isinstance(value, types.IntType))
        self.assertEquals(8443, value)

    def test_get_item_does_not_exist(self):
        self.assertRaises(NoOptionError, self.cfgParser.get, "rhsm", "this_isnt_a_thing")

    def test_get_int_un_set(self):
        value = self.cfgParser.get_int("server", "proxy_port")
        self.assertEquals(None, value)

    def test_get_int_does_not_exist(self):
        self.assertRaises(NoOptionError, self.cfgParser.get_int, "rhsm", "this_isnt_a_thing")

    def test_get_int_not_an_int(self):
        self.assertRaises(ValueError, self.cfgParser.get_int, "rhsm", "baseurl")

    def test_get_int_big_int(self):
        value = self.cfgParser.get_int("foo", "bigger_than_32_bit")
        self.assertEquals(21474836470, value)
        value = self.cfgParser.get_int("foo", "bigger_than_64_bit")
        self.assertEquals(123456789009876543211234567890, value)
Esempio n. 14
0
    def setUp(self):
        # create a temp file for use as a config file. This should get cleaned
        # up magically at the end of the run.
        self.fid = NamedTemporaryFile(mode="w+b", suffix=".tmp")
        self.fid.write(TEST_CONFIG)
        self.fid.seek(0)

        self.cfgParser = RhsmConfigParser(self.fid.name)
Esempio n. 15
0
class ConfigTests(unittest.TestCase):

    def setUp(self):
        # create a temp file for use as a config file. This should get cleaned
        # up magically at the end of the run.
        self.fid = NamedTemporaryFile(mode='w+b', suffix='.tmp')
        self.fid.write(TEST_CONFIG)
        self.fid.seek(0)

        self.cfgParser = RhsmConfigParser(self.fid.name)

    def testRead(self):
        self.assertEquals(self.cfgParser.get('server', 'hostname'), 'server.example.conf')

    def testSetd(self):
        self.cfgParser.set('rhsm', 'baseurl', 'cod')
        self.assertEquals(self.cfgParser.get('rhsm', 'baseurl'), 'cod')
Esempio n. 16
0
class TestConfigDBusObject(DBusObjectTest, TestUtilsMixin):
    def setUp(self):
        super(TestConfigDBusObject, self).setUp()
        self.proxy = self.proxy_for(ConfigDBusObject.default_dbus_path)
        self.interface = dbus.Interface(self.proxy, constants.CONFIG_INTERFACE)

    def dbus_objects(self):
        self.fid = self.write_temp_file(TEST_CONFIG)
        self.addCleanup(self.fid.close)
        self.parser = RhsmConfigParser(self.fid.name)
        return [(ConfigDBusObject, {"parser": self.parser})]

    def test_get_all(self):
        def assertions(*args):
            result = args[0]
            self.assertIn("server", result)

        dbus_method_args = [""]
        self.dbus_request(assertions, self.interface.GetAll, dbus_method_args)

    def test_get_property(self):
        def assertions(*args):
            result = args[0]
            self.assertIn("server.example.com", result)

        dbus_method_args = ["server.hostname", ""]
        self.dbus_request(assertions, self.interface.Get, dbus_method_args)

    def test_get_section(self):
        def assertions(*args):
            result = args[0]
            self.assertIn("hostname", result)

        dbus_method_args = ["server", ""]
        self.dbus_request(assertions, self.interface.Get, dbus_method_args)

    def test_set(self):
        def assertions(*args):
            self.assertEqual("new", self.parser.get("server", "hostname"))

        dbus_method_args = ["server.hostname", "new", ""]
        self.dbus_request(assertions, self.interface.Set, dbus_method_args)

    def test_set_section_fails(self):
        dbus_method_args = ["server", "new", ""]

        with self.assertRaisesRegex(dbus.DBusException,
                                    r"Setting an entire section is not.*"):
            self.dbus_request(None, self.interface.Set, dbus_method_args)
Esempio n. 17
0
class TestConfigDBusObject(DBusObjectTest, TestUtilsMixin):
    def setUp(self):
        super(TestConfigDBusObject, self).setUp()
        self.proxy = self.proxy_for(ConfigDBusObject.default_dbus_path)
        self.interface = dbus.Interface(self.proxy, constants.CONFIG_INTERFACE)

    def dbus_objects(self):
        self.fid = self.write_temp_file(TEST_CONFIG)
        self.addCleanup(self.fid.close)
        self.parser = RhsmConfigParser(self.fid.name)
        return [(ConfigDBusObject, {'parser': self.parser})]

    def test_get_all(self):
        def assertions(*args):
            result = args[0]
            self.assertIn("server", result)

        dbus_method_args = ['']
        self.dbus_request(assertions, self.interface.GetAll, dbus_method_args)

    def test_get_property(self):
        def assertions(*args):
            result = args[0]
            self.assertIn('server.example.com', result)

        dbus_method_args = ['server.hostname', '']
        self.dbus_request(assertions, self.interface.Get, dbus_method_args)

    def test_get_section(self):
        def assertions(*args):
            result = args[0]
            self.assertIn('hostname', result)

        dbus_method_args = ['server', '']
        self.dbus_request(assertions, self.interface.Get, dbus_method_args)

    def test_set(self):
        def assertions(*args):
            self.assertEqual('new', self.parser.get('server', 'hostname'))

        dbus_method_args = ['server.hostname', 'new', '']
        self.dbus_request(assertions, self.interface.Set, dbus_method_args)

    def test_set_section_fails(self):
        dbus_method_args = ['server', 'new', '']

        with six.assertRaisesRegex(self, dbus.DBusException, r'Setting an entire section is not.*'):
            self.dbus_request(None, self.interface.Set, dbus_method_args)
Esempio n. 18
0
 def setUp(self):
     self.fid = write_temp_file(self.cfgfile_data)
     self.cfgParser = RhsmConfigParser(self.fid.name)
Esempio n. 19
0
 def setUp(self):
     super(BaseConfigTest, self).setUp()
     self.fid = self.write_temp_file(TEST_CONFIG)
     self.parser = RhsmConfigParser(self.fid.name)
     self.config = Config(self.parser)
     self.addCleanup(self.fid.close)
Esempio n. 20
0
 def dbus_objects(self):
     self.fid = self.write_temp_file(TEST_CONFIG)
     self.addCleanup(self.fid.close)
     self.parser = RhsmConfigParser(self.fid.name)
     return [(ConfigDBusObject, {"parser": self.parser})]
Esempio n. 21
0
 def test_persist(self):
     self.config['foo'] = {'hello': 'world'}
     self.config.persist()
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual('world', reparsed.get('foo', 'hello'))
     self.assertRaises(NoOptionError, reparsed.get, 'foo', 'quux')
Esempio n. 22
0
 def test_auto_persists(self):
     config = Config(self.parser, auto_persist=True)
     config['foo'] = {'hello': 'world'}
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual('world', reparsed.get('foo', 'hello'))
     self.assertRaises(NoOptionError, reparsed.get, 'foo', 'quux')
Esempio n. 23
0
 def test_does_not_auto_persist_by_default(self):
     config = Config(self.parser, auto_persist=False)
     config["foo"] = {"hello": "world"}
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual("baz", reparsed.get("foo", "quux"))
     self.assertRaises(NoOptionError, reparsed.get, "foo", "hello")
Esempio n. 24
0
 def test_auto_persists(self):
     config = Config(self.parser, auto_persist=True)
     config["foo"] = {"hello": "world"}
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual("world", reparsed.get("foo", "hello"))
     self.assertRaises(NoOptionError, reparsed.get, "foo", "quux")
Esempio n. 25
0
 def test_persist(self):
     self.config["foo"] = {"hello": "world"}
     self.config.persist()
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual("world", reparsed.get("foo", "hello"))
     self.assertRaises(NoOptionError, reparsed.get, "foo", "quux")
Esempio n. 26
0
 def test_does_not_auto_persist_by_default(self):
     config = Config(self.parser, auto_persist=False)
     config['foo'] = {'hello': 'world'}
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual('baz', reparsed.get('foo', 'quux'))
     self.assertRaises(NoOptionError, reparsed.get, 'foo', 'hello')
Esempio n. 27
0
 def test_does_not_auto_persist_by_default(self):
     config = Config(self.parser, auto_persist=False)
     config['foo'] = {'hello': 'world'}
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual('baz', reparsed.get('foo', 'quux'))
     self.assertRaises(NoOptionError, reparsed.get, 'foo', 'hello')
Esempio n. 28
0
 def test_auto_persists(self):
     config = Config(self.parser, auto_persist=True)
     config['foo'] = {'hello': 'world'}
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual('world', reparsed.get('foo', 'hello'))
     self.assertRaises(NoOptionError, reparsed.get, 'foo', 'quux')
Esempio n. 29
0
 def test_persist(self):
     self.config['foo'] = {'hello': 'world'}
     self.config.persist()
     reparsed = RhsmConfigParser(self.fid.name)
     self.assertEqual('world', reparsed.get('foo', 'hello'))
     self.assertRaises(NoOptionError, reparsed.get, 'foo', 'quux')
Esempio n. 30
0
 def dbus_objects(self):
     self.fid = self.write_temp_file(TEST_CONFIG)
     self.addCleanup(self.fid.close)
     self.parser = RhsmConfigParser(self.fid.name)
     return [(ConfigDBusObject, {'parser': self.parser})]