Beispiel #1
0
 def test_unregister_missing(self):
     existing_sec = make_secret()
     secret.register([existing_sec])
     missing_sec = make_secret()
     res = secret.unregister([missing_sec["uuid"], existing_sec["uuid"]])
     self.assertEqual(res, response.success())
     self.assertEqual({}, self.connection.secrets)
Beispiel #2
0
 def test_unregister_missing(self):
     existing_sec = make_secret()
     secret.register([existing_sec])
     missing_sec = make_secret()
     res = secret.unregister([missing_sec["uuid"], existing_sec["uuid"]])
     self.assertEqual(res, response.success())
     self.assertEqual({}, self.connection.secrets)
Beispiel #3
0
 def test_unregister_existing(self):
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     secret.register([sec1, sec2])
     res = secret.unregister([sec1["uuid"]])
     self.assertEqual(res, response.success())
     self.assertNotIn(sec1["uuid"], self.connection.secrets)
     self.assertIn(sec2["uuid"], self.connection.secrets)
Beispiel #4
0
 def test_unregister_existing(self):
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     secret.register([sec1, sec2])
     res = secret.unregister([sec1["uuid"]])
     self.assertEqual(res, response.success())
     self.assertNotIn(sec1["uuid"], self.connection.secrets)
     self.assertIn(sec2["uuid"], self.connection.secrets)
Beispiel #5
0
 def test_register_change_usage_id(self):
     sec = make_secret(usage_id="ovirt/provider_uuid/secert_uuid")
     secret.register([sec])
     # Change usage id
     sec["usageID"] = "ovirt/domain_uuid/secret_uuid"
     res = secret.register([sec])
     self.assertEqual(res, response.success())
     virsec = self.connection.secrets[sec["uuid"]]
     self.assertEqual("ovirt/domain_uuid/secret_uuid", virsec.usage_id)
Beispiel #6
0
 def test_register_change_usage_id(self):
     sec = make_secret(usage_id="ovirt/provider_uuid/secert_uuid")
     secret.register([sec])
     # Change usage id
     sec["usageID"] = "ovirt/domain_uuid/secret_uuid"
     res = secret.register([sec])
     self.assertEqual(res, response.success())
     virsec = self.connection.secrets[sec["uuid"]]
     self.assertEqual("ovirt/domain_uuid/secret_uuid", virsec.usage_id)
Beispiel #7
0
 def test_register_replace(self):
     # Register 2 secrets
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     secret.register([sec1, sec2])
     # Replace existing secret value
     sec2["password"] = make_password("sec2 new password")
     res = secret.register([sec2])
     self.assertEqual(res, response.success())
     virsec1 = self.connection.secrets[sec1["uuid"]]
     self.assertEqual("sec1 password", virsec1.value)
     virsec2 = self.connection.secrets[sec2["uuid"]]
     self.assertEqual("sec2 new password", virsec2.value)
Beispiel #8
0
 def test_register_replace(self):
     # Register 2 secrets
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     secret.register([sec1, sec2])
     # Replace existing secret value
     sec2["password"] = make_password("sec2 new password")
     res = secret.register([sec2])
     self.assertEqual(res, response.success())
     virsec1 = self.connection.secrets[sec1["uuid"]]
     self.assertEqual("sec1 password", virsec1.value)
     virsec2 = self.connection.secrets[sec2["uuid"]]
     self.assertEqual("sec2 new password", virsec2.value)
Beispiel #9
0
    def test_register_libvirt_error(self):
        def fail(xml):
            raise vmfakelib.Error(libvirt.VIR_ERR_INTERNAL_ERROR)

        self.connection.secretDefineXML = fail
        res = secret.register([make_secret()])
        self.assertEqual(res, response.error("secretRegisterErr"))
Beispiel #10
0
 def test_register_new(self):
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     res = secret.register([sec1, sec2])
     self.assertEqual(res, response.success())
     virsec1 = self.connection.secrets[sec1["uuid"]]
     self.assertEqual("sec1 password", virsec1.value)
     virsec2 = self.connection.secrets[sec2["uuid"]]
     self.assertEqual("sec2 password", virsec2.value)
Beispiel #11
0
 def test_register_new(self):
     sec1 = make_secret(password="******")
     sec2 = make_secret(password="******")
     res = secret.register([sec1, sec2])
     self.assertEqual(res, response.success())
     virsec1 = self.connection.secrets[sec1["uuid"]]
     self.assertEqual("sec1 password", virsec1.value)
     virsec2 = self.connection.secrets[sec2["uuid"]]
     self.assertEqual("sec2 password", virsec2.value)
Beispiel #12
0
 def test_register_clear(self):
     self.connection.secrets = {
         "uuid1": vmfakelib.Secret(self.connection, "uuid1", "ceph",
                                   "ovirt/name1", None),
         "uuid2": vmfakelib.Secret(self.connection, "uuid2", "ceph",
                                   "name2", None),
     }
     sec = make_secret()
     res = secret.register([sec], clear=True)
     # Should succeed
     self.assertEqual(res, response.success())
     # Should remove existing ovirt secrets
     self.assertNotIn("uuid1", self.connection.secrets)
     # Should keep non-ovirt secrets
     self.assertIn("uuid2", self.connection.secrets)
     # Should register new secret
     virsec = self.connection.secrets[sec["uuid"]]
     self.assertEqual(sec["password"].value, virsec.value)
Beispiel #13
0
 def test_register_clear(self):
     self.connection.secrets = {
         "uuid1":
         vmfakelib.Secret(self.connection, "uuid1", "ceph", "ovirt/name1",
                          None),
         "uuid2":
         vmfakelib.Secret(self.connection, "uuid2", "ceph", "name2", None),
     }
     sec = make_secret()
     res = secret.register([sec], clear=True)
     # Should succeed
     self.assertEqual(res, response.success())
     # Should remove existing ovirt secrets
     self.assertNotIn("uuid1", self.connection.secrets)
     # Should keep non-ovirt secrets
     self.assertIn("uuid2", self.connection.secrets)
     # Should register new secret
     virsec = self.connection.secrets[sec["uuid"]]
     self.assertEqual(sec["password"].value, virsec.value)
Beispiel #14
0
 def test_register_validation(self):
     res = secret.register([{"invalid": "secret"}])
     self.assertEqual(res, response.error("secretBadRequestErr"))
Beispiel #15
0
 def test_register_libvirt_error(self):
     def fail(xml):
         raise vmfakelib.Error(libvirt.VIR_ERR_INTERNAL_ERROR)
     self.connection.secretDefineXML = fail
     res = secret.register([make_secret()])
     self.assertEqual(res, response.error("secretRegisterErr"))
Beispiel #16
0
 def test_register_validation(self):
     res = secret.register([{"invalid": "secret"}])
     self.assertEqual(res, response.error("secretBadRequestErr"))