Ejemplo n.º 1
0
 def test_control_mode(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     template = "/etc/control/mode"
     target_file = os.path.join(tmpdir, template[1:])
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     self.assertEqual(0o100755, os.stat(target_file).st_mode)
 def test_control_mode(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     template = "/etc/control/mode"
     target_file = os.path.join(tmpdir, template[1:])
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     self.assertEqual(0o100755, os.stat(target_file).st_mode)
Ejemplo n.º 3
0
 def test_install_config_subhash(self):
     tpath = self.write_config(CONFIG_SUBHASH)
     tmpdir = tempfile.mkdtemp()
     apply_config.install_config([tpath], TEMPLATES, tmpdir, False,
                                 'OpenStack::Config')
     for path, obj in OUTPUT.items():
         self.check_output_file(tmpdir, path, obj)
 def test_install_config_subhash(self):
     tpath = self.write_config(CONFIG_SUBHASH)
     tmpdir = tempfile.mkdtemp()
     apply_config.install_config(
         [tpath], TEMPLATES, tmpdir, False, 'OpenStack::Config')
     for path, obj in OUTPUT.items():
         self.check_output_file(tmpdir, path, obj)
 def test_control_chown(self, chown_mock):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     apply_config.install_config([path], CHOWN_TEMPLATES, tmpdir, False)
     chown_mock.assert_has_calls([mock.call(mock.ANY, 0, -1),   # uid
                                  mock.call(mock.ANY, 0, -1),   # username
                                  mock.call(mock.ANY, -1, 0),   # gid
                                  mock.call(mock.ANY, -1, 0)],  # groupname
                                 any_order=True)
Ejemplo n.º 6
0
 def test_control_chown(self, chown_mock):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     apply_config.install_config([path], CHOWN_TEMPLATES, tmpdir, False)
     chown_mock.assert_has_calls([mock.call(mock.ANY, 0, -1),   # uid
                                  mock.call(mock.ANY, 0, -1),   # username
                                  mock.call(mock.ANY, -1, 0),   # gid
                                  mock.call(mock.ANY, -1, 0)],  # groupname
                                 any_order=True)
Ejemplo n.º 7
0
 def test_install_config(self):
     fd, path = tempfile.mkstemp()
     with os.fdopen(fd, 'w') as t:
         t.write(json.dumps(CONFIG))
         t.flush()
     tmpdir = tempfile.mkdtemp()
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     for path, contents in OUTPUT.items():
         full_path = os.path.join(tmpdir, path[1:])
         assert os.path.exists(full_path)
         self.assertEqual(open(full_path).read(), contents)
Ejemplo n.º 8
0
 def test_delete_if_not_allowed_empty(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     template = "/etc/control/allow_empty"
     target_file = os.path.join(tmpdir, template[1:])
     # Touch the file
     os.makedirs(os.path.dirname(target_file))
     open(target_file, 'a').close()
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     # File should be gone
     self.assertFalse(os.path.exists(target_file))
 def test_delete_if_not_allowed_empty(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     template = "/etc/control/allow_empty"
     target_file = os.path.join(tmpdir, template[1:])
     # Touch the file
     os.makedirs(os.path.dirname(target_file))
     open(target_file, 'a').close()
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     # File should be gone
     self.assertFalse(os.path.exists(target_file))
Ejemplo n.º 10
0
 def test_respect_file_permissions(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     template = "/etc/keystone/keystone.conf"
     target_file = os.path.join(tmpdir, template[1:])
     os.makedirs(os.path.dirname(target_file))
     # File doesn't exist, use the default mode (644)
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     self.assertEqual(0o100644, os.stat(target_file).st_mode)
     self.assertEqual(OUTPUT[template].body, open(target_file).read())
     # Set a different mode:
     os.chmod(target_file, 0o600)
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     # The permissions should be preserved
     self.assertEqual(0o100600, os.stat(target_file).st_mode)
     self.assertEqual(OUTPUT[template].body, open(target_file).read())
Ejemplo n.º 11
0
 def test_respect_file_permissions(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     template = "/etc/keystone/keystone.conf"
     target_file = os.path.join(tmpdir, template[1:])
     os.makedirs(os.path.dirname(target_file))
     # File doesn't exist, use the default mode (644)
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     self.assertEqual(0o100644, os.stat(target_file).st_mode)
     self.assertEqual(OUTPUT[template].body, open(target_file).read())
     # Set a different mode:
     os.chmod(target_file, 0o600)
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     # The permissions should be preserved
     self.assertEqual(0o100600, os.stat(target_file).st_mode)
     self.assertEqual(OUTPUT[template].body, open(target_file).read())
Ejemplo n.º 12
0
 def test_respect_file_permissions(self):
     fd, path = tempfile.mkstemp()
     with os.fdopen(fd, 'w') as t:
         t.write(json.dumps(CONFIG))
         t.flush()
     tmpdir = tempfile.mkdtemp()
     template = "/etc/keystone/keystone.conf"
     target_file = os.path.join(tmpdir, template[1:])
     os.makedirs(os.path.dirname(target_file))
     # File doesn't exist, use the default mode (644)
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     self.assertEqual(os.stat(target_file).st_mode, 0o100644)
     self.assertEqual(open(target_file).read(), OUTPUT[template])
     # Set a different mode:
     os.chmod(target_file, 0o600)
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     # The permissions should be preserved
     self.assertEqual(os.stat(target_file).st_mode, 0o100600)
     self.assertEqual(open(target_file).read(), OUTPUT[template])
Ejemplo n.º 13
0
 def test_install_config(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     for path, obj in OUTPUT.items():
         self.check_output_file(tmpdir, path, obj)
Ejemplo n.º 14
0
 def test_install_config(self):
     path = self.write_config(CONFIG)
     tmpdir = tempfile.mkdtemp()
     apply_config.install_config([path], TEMPLATES, tmpdir, False)
     for path, obj in OUTPUT.items():
         self.check_output_file(tmpdir, path, obj)