Пример #1
0
 def test_group_positive(self):
     oacf = oac_file.OacFile('')
     groups = grp.getgrall()
     for name in [group[0] for group in groups]:
         oacf.group = name
     for gid in [group[2] for group in groups]:
         oacf.group = gid
Пример #2
0
 def test_owner_positive(self):
     oacf = oac_file.OacFile('')
     users = pwd.getpwall()
     for name in [user[0] for user in users]:
         oacf.owner = name
     for uid in [user[2] for user in users]:
         oacf.owner = uid
Пример #3
0
 def test_mode_string(self):
     oacf = oac_file.OacFile('')
     mode = '0644'
     try:
         oacf.mode = mode
     except exc.ConfigException as e:
         self.assertIn("mode '%s' is not numeric" % mode, str(e))
Пример #4
0
    def test_mode_range(self):
        oacf = oac_file.OacFile('')
        for mode in [-1, 0o1000]:
            try:
                oacf.mode = mode
            except exc.ConfigException as e:
                self.assertTrue("mode '%#o' out of range" % mode in str(e),
                                "mode: %#o" % mode)

        for mode in [0, 0o777]:
            oacf.mode = mode
Пример #5
0
 def test_group_negative(self):
     oacf = oac_file.OacFile('')
     try:
         group = -1
         oacf.group = group
     except exc.ConfigException as e:
         self.assertIn(
             "group '%s' not found in group database" % group, str(e))
     try:
         group = "za"
         oacf.group = group
     except exc.ConfigException as e:
         self.assertIn(
             "group '%s' not found in group database" % group, str(e))
Пример #6
0
 def test_owner_negative(self):
     oacf = oac_file.OacFile('')
     try:
         user = -1
         oacf.owner = user
     except exc.ConfigException as e:
         self.assertIn(
             "owner '%s' not found in passwd database" % user, str(e))
     try:
         user = "******"
         oacf.owner = user
     except exc.ConfigException as e:
         self.assertIn(
             "owner '%s' not found in passwd database" % user, str(e))
Пример #7
0
def build_tree(templates, config):
    """Return a map of filenames to OacFiles."""
    res = {}
    for in_file, out_file in templates:
        try:
            body = render_template(in_file, config)
            ctrl_file = in_file + CONTROL_FILE_SUFFIX
            ctrl_dict = {}
            if os.path.isfile(ctrl_file):
                with open(ctrl_file) as cf:
                    ctrl_body = cf.read()
                ctrl_dict = yaml.safe_load(ctrl_body) or {}
            if not isinstance(ctrl_dict, dict):
                raise exc.ConfigException("header is not a dict: %s" % in_file)
            res[out_file] = oac_file.OacFile(body, **ctrl_dict)
        except exc.ConfigException as e:
            e.args += in_file,
            raise
    return res
Пример #8
0
}

# config for example tree - with subhash
CONFIG_SUBHASH = {
    "OpenStack::Config": {
        "x": "foo",
        "database": {
            "url": "sqlite:///blah"
        }
    }
}

# expected output for example tree
OUTPUT = {
    "/etc/glance/script.conf":
    oac_file.OacFile("foo\n"),
    "/etc/keystone/keystone.conf":
    oac_file.OacFile("[foo]\ndatabase = sqlite:///blah\n"),
    "/etc/control/empty":
    oac_file.OacFile("foo\n"),
    "/etc/control/allow_empty":
    oac_file.OacFile("").set('allow_empty', False),
    "/etc/control/mode":
    oac_file.OacFile("lorem modus\n").set('mode', 0o755),
}
TEMPLATE_PATHS = OUTPUT.keys()

# expected output for chown tests
# separated out to avoid needing to mock os.chown for most tests
CHOWN_TEMPLATES = os.path.join(os.path.dirname(__file__), 'chown_templates')
CHOWN_OUTPUT = {
    "l": [1, 2],
}

# config for example tree - with subhash
CONFIG_SUBHASH = {
    "OpenStack::Config": {
        "x": "foo",
        "database": {
            "url": "sqlite:///blah"
        }
    }
}

# expected output for example tree
OUTPUT = {
    "/etc/glance/script.conf": oac_file.OacFile(
        "foo\n"),
    "/etc/keystone/keystone.conf": oac_file.OacFile(
        "[foo]\ndatabase = sqlite:///blah\n"),
    "/etc/control/empty": oac_file.OacFile(
        "foo\n"),
    "/etc/control/allow_empty": oac_file.OacFile(
        "").set('allow_empty', False),
    "/etc/control/mode": oac_file.OacFile(
        "lorem modus\n").set('mode', 0o755),
}
TEMPLATE_PATHS = OUTPUT.keys()

# expected output for chown tests
# separated out to avoid needing to mock os.chown for most tests
CHOWN_TEMPLATES = os.path.join(os.path.dirname(__file__), 'chown_templates')
CHOWN_OUTPUT = {