示例#1
0
    def test_inject_data_key(self):

        vfs = vfsguestfs.VFSGuestFS("/some/file", "qcow2")
        vfs.setup()

        diskapi._inject_key_into_fs("mysshkey", vfs)

        self.assertIn("/root/.ssh", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/root/.ssh"], {
            'isdir': True,
            'gid': 0,
            'uid': 0,
            'mode': 0o700
        })
        self.assertIn("/root/.ssh/authorized_keys", vfs.handle.files)
        self.assertEqual(
            vfs.handle.files["/root/.ssh/authorized_keys"], {
                'isdir': False,
                'content': "Hello World\n# The following ssh " +
                "key was injected by Nova\nmysshkey\n",
                'gid': 100,
                'uid': 100,
                'mode': 0o600
            })

        vfs.teardown()
示例#2
0
    def test_inject_data_key_with_selinux_append_with_newline(self):

        vfs = vfsguestfs.VFSGuestFS("/some/file", "qcow2")
        vfs.setup()

        vfs.replace_file("/etc/rc.d/rc.local", "#!/bin/sh\necho done")
        vfs.make_path("etc/selinux")
        vfs.make_path("etc/rc.d")
        diskapi._inject_key_into_fs("mysshkey", vfs)

        self.assertIn("/etc/rc.d/rc.local", vfs.handle.files)
        self.assertEqual(
            vfs.handle.files["/etc/rc.d/rc.local"], {
                'isdir':
                False,
                'content':
                "#!/bin/sh\necho done\n# Added "
                "by Nova to ensure injected ssh keys have "
                "the right context\nrestorecon -RF "
                "root/.ssh 2>/dev/null || :\n",
                'gid':
                100,
                'uid':
                100,
                'mode':
                0o700
            })
        vfs.teardown()
示例#3
0
    def test_inject_data_key_with_selinux(self):

        vfs = vfsguestfs.VFSGuestFS("/some/file", "qcow2")
        vfs.setup()

        vfs.make_path("etc/selinux")
        vfs.make_path("etc/rc.d")
        diskapi._inject_key_into_fs("mysshkey", vfs)

        self.assertIn("/etc/rc.d/rc.local", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/etc/rc.d/rc.local"],
                         {'isdir': False,
                          'content': "Hello World#!/bin/sh\n# Added by " +
                                     "Nova to ensure injected ssh keys " +
                                     "have the right context\nrestorecon " +
                                     "-RF root/.ssh 2>/dev/null || :\n",
                          'gid': 100,
                          'uid': 100,
                          'mode': 0o700})

        self.assertIn("/root/.ssh", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/root/.ssh"],
                         {'isdir': True, 'gid': 0, 'uid': 0, 'mode': 0o700})
        self.assertIn("/root/.ssh/authorized_keys", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/root/.ssh/authorized_keys"],
                         {'isdir': False,
                          'content': "Hello World\n# The following ssh " +
                                     "key was injected by Nova\nmysshkey\n",
                          'gid': 100,
                          'uid': 100,
                          'mode': 0o600})

        vfs.teardown()
示例#4
0
    def test_inject_data_key_with_selinux(self):

        vfs = vfsguestfs.VFSGuestFS("/some/file", "qcow2")
        vfs.setup()

        vfs.make_path("etc/selinux")
        vfs.make_path("etc/rc.d")
        diskapi._inject_key_into_fs("mysshkey", vfs)

        self.assertIn("/etc/rc.d/rc.local", vfs.handle.files)
        self.assertEqual(
            vfs.handle.files["/etc/rc.d/rc.local"], {
                'isdir':
                False,
                'content':
                "Hello World#!/bin/sh\n# Added by " +
                "Nova to ensure injected ssh keys " +
                "have the right context\nrestorecon " +
                "-RF root/.ssh 2>/dev/null || :\n",
                'gid':
                100,
                'uid':
                100,
                'mode':
                0o700
            })

        self.assertIn("/root/.ssh", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/root/.ssh"], {
            'isdir': True,
            'gid': 0,
            'uid': 0,
            'mode': 0o700
        })
        self.assertIn("/root/.ssh/authorized_keys", vfs.handle.files)
        self.assertEqual(
            vfs.handle.files["/root/.ssh/authorized_keys"], {
                'isdir': False,
                'content': "Hello World\n# The following ssh " +
                "key was injected by Nova\nmysshkey\n",
                'gid': 100,
                'uid': 100,
                'mode': 0o600
            })

        vfs.teardown()
示例#5
0
    def test_inject_data_key(self):

        vfs = vfsguestfs.VFSGuestFS("/some/file", "qcow2")
        vfs.setup()

        diskapi._inject_key_into_fs("mysshkey", vfs)

        self.assertIn("/root/.ssh", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/root/.ssh"],
                         {'isdir': True, 'gid': 0, 'uid': 0, 'mode': 0o700})
        self.assertIn("/root/.ssh/authorized_keys", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/root/.ssh/authorized_keys"],
                         {'isdir': False,
                          'content': "Hello World\n# The following ssh " +
                                     "key was injected by Nova\nmysshkey\n",
                          'gid': 100,
                          'uid': 100,
                          'mode': 0o600})

        vfs.teardown()
示例#6
0
    def test_inject_data_key_with_selinux_append_with_newline(self):

        vfs = vfsguestfs.VFSGuestFS("/some/file", "qcow2")
        vfs.setup()

        vfs.replace_file("/etc/rc.d/rc.local", "#!/bin/sh\necho done")
        vfs.make_path("etc/selinux")
        vfs.make_path("etc/rc.d")
        diskapi._inject_key_into_fs("mysshkey", vfs)

        self.assertIn("/etc/rc.d/rc.local", vfs.handle.files)
        self.assertEqual(vfs.handle.files["/etc/rc.d/rc.local"],
                {'isdir': False,
                 'content': "#!/bin/sh\necho done\n# Added "
                            "by Nova to ensure injected ssh keys have "
                            "the right context\nrestorecon -RF "
                            "root/.ssh 2>/dev/null || :\n",
                 'gid': 100,
                 'uid': 100,
                 'mode': 0o700})
        vfs.teardown()