Exemple #1
0
    def test_credential_get_name(self):
        cred11 = self._cred_test_obj(1, 1)
        cred11_id = cdb.add_credential(cred11.tenant, cred11.cname, cred11.usr,
                                       cred11.pwd).credential_id
        cred21 = self._cred_test_obj(2, 1)
        cred21_id = cdb.add_credential(cred21.tenant, cred21.cname, cred21.usr,
                                       cred21.pwd).credential_id
        cred22 = self._cred_test_obj(2, 2)
        cred22_id = cdb.add_credential(cred22.tenant, cred22.cname, cred22.usr,
                                       cred22.pwd).credential_id
        self.assertNotEqual(cred11_id, cred21_id)
        self.assertNotEqual(cred11_id, cred22_id)
        self.assertNotEqual(cred21_id, cred22_id)

        cred = cdb.get_credential_name(cred11.tenant, cred11.cname)
        self._assert_equal(cred, cred11)
        cred = cdb.get_credential_name(cred21.tenant, cred21.cname)
        self._assert_equal(cred, cred21)
        cred = cdb.get_credential_name(cred22.tenant, cred22.cname)
        self._assert_equal(cred, cred22)

        with testtools.ExpectedException(c_exc.CredentialNameNotFound):
            cdb.get_credential_name(cred11.tenant, "dummyCredentialName")
        with testtools.ExpectedException(c_exc.CredentialNameNotFound):
            cdb.get_credential_name(cred11.tenant, cred22.cname)
Exemple #2
0
    def test_credential_get_id(self):
        cred11 = self._cred_test_obj(1, 1)
        cred11_id = cdb.add_credential(cred11.tenant, cred11.cname, cred11.usr,
                                       cred11.pwd).credential_id
        cred21 = self._cred_test_obj(2, 1)
        cred21_id = cdb.add_credential(cred21.tenant, cred21.cname, cred21.usr,
                                       cred21.pwd).credential_id
        cred22 = self._cred_test_obj(2, 2)
        cred22_id = cdb.add_credential(cred22.tenant, cred22.cname, cred22.usr,
                                       cred22.pwd).credential_id

        cred = cdb.get_credential(cred11.tenant, cred11_id)
        self._assert_equal(cred, cred11)
        cred = cdb.get_credential(cred21.tenant, cred21_id)
        self._assert_equal(cred, cred21)
        cred = cdb.get_credential(cred21.tenant, cred22_id)
        self._assert_equal(cred, cred22)

        with testtools.ExpectedException(c_exc.CredentialNotFound):
            cdb.get_credential(cred11.tenant, "dummyCredentialId")
        with testtools.ExpectedException(c_exc.CredentialNotFound):
            cdb.get_credential(cred11.tenant, cred21_id)
        with testtools.ExpectedException(c_exc.CredentialNotFound):
            cdb.get_credential(cred21.tenant, cred11_id)

        cred_all_t1 = cdb.get_all_credentials(cred11.tenant)
        self.assertEqual(len(cred_all_t1), 1)
        cred_all_t2 = cdb.get_all_credentials(cred21.tenant)
        self.assertEqual(len(cred_all_t2), 2)
        cred_all_t3 = cdb.get_all_credentials("dummyTenant")
        self.assertEqual(len(cred_all_t3), 0)
Exemple #3
0
 def test_credential_delete_all_n1kv(self):
     cred_nexus_1 = self._cred_test_obj('nexus', 1)
     cred_nexus_2 = self._cred_test_obj('nexus', 2)
     cred_n1kv_1 = self.CredObj('n1kv-1', 'cisco', '123456', 'n1kv')
     cred_n1kv_2 = self.CredObj('n1kv-2', 'cisco', '123456', 'n1kv')
     cred_nexus_1_id = cdb.add_credential(
         cred_nexus_1.cname, cred_nexus_1.usr,
         cred_nexus_1.pwd, cred_nexus_1.ctype).credential_id
     cred_nexus_2_id = cdb.add_credential(
         cred_nexus_2.cname, cred_nexus_2.usr,
         cred_nexus_2.pwd, cred_nexus_2.ctype).credential_id
     cred_n1kv_1_id = cdb.add_credential(
         cred_n1kv_1.cname, cred_n1kv_1.usr,
         cred_n1kv_1.pwd, cred_n1kv_1.ctype).credential_id
     cred_n1kv_2_id = cdb.add_credential(
         cred_n1kv_2.cname, cred_n1kv_2.usr,
         cred_n1kv_2.pwd, cred_n1kv_2.ctype).credential_id
     cdb.delete_all_n1kv_credentials()
     cred = cdb.get_credential(cred_nexus_1_id)
     self.assertIsNotNone(cred)
     cred = cdb.get_credential(cred_nexus_2_id)
     self.assertIsNotNone(cred)
     self.assertRaises(c_exc.CredentialNotFound,
                       cdb.get_credential, cred_n1kv_1_id)
     self.assertRaises(c_exc.CredentialNotFound,
                       cdb.get_credential, cred_n1kv_2_id)
 def test_credential_delete_all_n1kv(self):
     cred_nexus_1 = self._cred_test_obj('nexus', 1)
     cred_nexus_2 = self._cred_test_obj('nexus', 2)
     cred_n1kv_1 = self.CredObj('n1kv-1', 'cisco', '123456', 'n1kv')
     cred_n1kv_2 = self.CredObj('n1kv-2', 'cisco', '123456', 'n1kv')
     cred_nexus_1_id = cdb.add_credential(
         cred_nexus_1.cname, cred_nexus_1.usr,
         cred_nexus_1.pwd, cred_nexus_1.ctype).credential_id
     cred_nexus_2_id = cdb.add_credential(
         cred_nexus_2.cname, cred_nexus_2.usr,
         cred_nexus_2.pwd, cred_nexus_2.ctype).credential_id
     cred_n1kv_1_id = cdb.add_credential(
         cred_n1kv_1.cname, cred_n1kv_1.usr,
         cred_n1kv_1.pwd, cred_n1kv_1.ctype).credential_id
     cred_n1kv_2_id = cdb.add_credential(
         cred_n1kv_2.cname, cred_n1kv_2.usr,
         cred_n1kv_2.pwd, cred_n1kv_2.ctype).credential_id
     cdb.delete_all_n1kv_credentials()
     cred = cdb.get_credential(cred_nexus_1_id)
     self.assertIsNotNone(cred)
     cred = cdb.get_credential(cred_nexus_2_id)
     self.assertIsNotNone(cred)
     self.assertRaises(c_exc.CredentialNotFound,
                       cdb.get_credential, cred_n1kv_1_id)
     self.assertRaises(c_exc.CredentialNotFound,
                       cdb.get_credential, cred_n1kv_2_id)
Exemple #5
0
 def initialize():
     for keys in _nexus_dict.keys():
         if keys[1] == const.USERNAME:
             try:
                 cdb.add_credential(TENANT, keys[0],
                                    _nexus_dict[keys[0], const.USERNAME],
                                    _nexus_dict[keys[0], const.PASSWORD])
             except cexc.CredentialAlreadyExists:
                 # We are quietly ignoring this, since it only happens
                 # if this class module is loaded more than once, in which
                 # case, the credentials are already populated
                 pass
Exemple #6
0
 def test_credential_add_dup(self):
     cred22 = self._cred_test_obj(2, 2)
     cred = cdb.add_credential(cred22.tenant, cred22.cname, cred22.usr,
                               cred22.pwd)
     self._assert_equal(cred, cred22)
     cred_id = cred.credential_id
     with testtools.ExpectedException(c_exc.CredentialAlreadyExists):
         cdb.add_credential(cred22.tenant, cred22.cname, cred22.usr,
                            cred22.pwd)
     cred = cdb.remove_credential(cred22.tenant, cred_id)
     self._assert_equal(cred, cred22)
     cred = cdb.remove_credential(cred22.tenant, cred_id)
     self.assertIsNone(cred)
 def test_credential_add_dup(self):
     cred22 = self._cred_test_obj(2, 2)
     cred = cdb.add_credential(
         cred22.cname, cred22.usr, cred22.pwd, cred22.ctype)
     self._assert_equal(cred, cred22)
     cred_id = cred.credential_id
     with testtools.ExpectedException(c_exc.CredentialAlreadyExists):
         cdb.add_credential(
             cred22.cname, cred22.usr, cred22.pwd, cred22.ctype)
     cred = cdb.remove_credential(cred_id)
     self._assert_equal(cred, cred22)
     cred = cdb.remove_credential(cred_id)
     self.assertIsNone(cred)
 def initialize():
     dev_dict = config.get_device_dictionary()
     for key in dev_dict:
         dev_id, dev_ip, dev_key = key
         if dev_key == const.USERNAME:
             try:
                 cdb.add_credential(
                     dev_ip, dev_dict[dev_id, dev_ip, const.USERNAME],
                     dev_dict[dev_id, dev_ip, const.PASSWORD], dev_id)
             except cexc.CredentialAlreadyExists:
                 # We are quietly ignoring this, since it only happens
                 # if this class module is loaded more than once, in
                 # which case, the credentials are already populated
                 pass
 def initialize():
     dev_dict = config.get_device_dictionary()
     for key in dev_dict:
         dev_id, dev_ip, dev_key = key
         if dev_key == const.USERNAME:
             try:
                 cdb.add_credential(
                     dev_ip,
                     dev_dict[dev_id, dev_ip, const.USERNAME],
                     dev_dict[dev_id, dev_ip, const.PASSWORD],
                     dev_id)
             except cexc.CredentialAlreadyExists:
                 # We are quietly ignoring this, since it only happens
                 # if this class module is loaded more than once, in
                 # which case, the credentials are already populated
                 pass
Exemple #10
0
 def create_credential(self, tenant_id, credential_name, user_name,
                       password):
     """Create a new credential."""
     LOG.debug(_("create_credential() called"))
     credential = cdb.add_credential(tenant_id, credential_name,
                                     user_name, password)
     return credential
Exemple #11
0
 def test_credential_add_remove(self):
     cred11 = self._cred_test_obj(1, 1)
     cred = cdb.add_credential(
         cred11.cname, cred11.usr, cred11.pwd, cred11.ctype)
     self._assert_equal(cred, cred11)
     cred_id = cred.credential_id
     cred = cdb.remove_credential(cred_id)
     self._assert_equal(cred, cred11)
     cred = cdb.remove_credential(cred_id)
     self.assertIsNone(cred)
Exemple #12
0
 def test_credential_add_remove(self):
     cred11 = self._cred_test_obj(1, 1)
     cred = cdb.add_credential(cred11.tenant, cred11.cname, cred11.usr,
                               cred11.pwd)
     self._assert_equal(cred, cred11)
     cred_id = cred.credential_id
     cred = cdb.remove_credential(cred11.tenant, cred_id)
     self._assert_equal(cred, cred11)
     cred = cdb.remove_credential(cred11.tenant, cred_id)
     self.assertIsNone(cred)
Exemple #13
0
    def test_credential_get_name(self):
        cred11 = self._cred_test_obj(1, 1)
        cred11_id = cdb.add_credential(
            cred11.cname, cred11.usr, cred11.pwd, cred11.ctype).credential_id
        cred21 = self._cred_test_obj(2, 1)
        cred21_id = cdb.add_credential(
            cred21.cname, cred21.usr, cred21.pwd, cred21.ctype).credential_id
        cred22 = self._cred_test_obj(2, 2)
        cred22_id = cdb.add_credential(
            cred22.cname, cred22.usr, cred22.pwd, cred22.ctype).credential_id
        self.assertNotEqual(cred11_id, cred21_id)
        self.assertNotEqual(cred11_id, cred22_id)
        self.assertNotEqual(cred21_id, cred22_id)

        cred = cdb.get_credential_name(cred11.cname)
        self._assert_equal(cred, cred11)
        cred = cdb.get_credential_name(cred21.cname)
        self._assert_equal(cred, cred21)
        cred = cdb.get_credential_name(cred22.cname)
        self._assert_equal(cred, cred22)

        with testtools.ExpectedException(c_exc.CredentialNameNotFound):
            cdb.get_credential_name("dummyCredentialName")
Exemple #14
0
    def test_credential_get_id(self):
        cred11 = self._cred_test_obj(1, 1)
        cred11_id = cdb.add_credential(
            cred11.cname, cred11.usr, cred11.pwd, cred11.ctype).credential_id
        cred21 = self._cred_test_obj(2, 1)
        cred21_id = cdb.add_credential(
            cred21.cname, cred21.usr, cred21.pwd, cred21.ctype).credential_id
        cred22 = self._cred_test_obj(2, 2)
        cred22_id = cdb.add_credential(
            cred22.cname, cred22.usr, cred22.pwd, cred22.ctype).credential_id

        cred = self._network_plugin.get_credential_details(cred11_id)
        self._assert_equal(cred, cred11)
        cred = self._network_plugin.get_credential_details(cred21_id)
        self._assert_equal(cred, cred21)
        cred = self._network_plugin.get_credential_details(cred22_id)
        self._assert_equal(cred, cred22)

        with testtools.ExpectedException(c_exc.CredentialNotFound):
            self._network_plugin.get_credential_details("dummyCredentialId")

        cred_all_t1 = self._network_plugin.get_all_credentials()
        self.assertEqual(len(cred_all_t1), 3)
Exemple #15
0
    def test_credential_get_id(self):
        cred11 = self._cred_test_obj(1, 1)
        cred11_id = cdb.add_credential(
            cred11.cname, cred11.usr, cred11.pwd, cred11.ctype).credential_id
        cred21 = self._cred_test_obj(2, 1)
        cred21_id = cdb.add_credential(
            cred21.cname, cred21.usr, cred21.pwd, cred21.ctype).credential_id
        cred22 = self._cred_test_obj(2, 2)
        cred22_id = cdb.add_credential(
            cred22.cname, cred22.usr, cred22.pwd, cred22.ctype).credential_id

        cred = self._network_plugin.get_credential_details(cred11_id)
        self._assert_equal(cred, cred11)
        cred = self._network_plugin.get_credential_details(cred21_id)
        self._assert_equal(cred, cred21)
        cred = self._network_plugin.get_credential_details(cred22_id)
        self._assert_equal(cred, cred22)

        with testtools.ExpectedException(c_exc.CredentialNotFound):
            self._network_plugin.get_credential_details("dummyCredentialId")

        cred_all_t1 = self._network_plugin.get_all_credentials()
        self.assertEqual(len(cred_all_t1), 3)
Exemple #16
0
 def test_credential_update(self):
     cred11 = self._cred_test_obj(1, 1)
     cred11_id = cdb.add_credential(cred11.cname, cred11.usr, cred11.pwd,
                                    cred11.ctype).credential_id
     cdb.update_credential(cred11_id)
     new_usr = "******"
     new_pwd = "new password"
     new_credential = cdb.update_credential(cred11_id, new_usr, new_pwd)
     expected_cred = self.CredObj(cred11.cname, new_usr, new_pwd,
                                  cred11.ctype)
     self._assert_equal(new_credential, expected_cred)
     new_credential = cdb.get_credential(cred11_id)
     self._assert_equal(new_credential, expected_cred)
     with testtools.ExpectedException(c_exc.CredentialNotFound):
         cdb.update_credential("dummyCredentialId", new_usr, new_pwd)
 def test_credential_update(self):
     cred11 = self._cred_test_obj(1, 1)
     cred11_id = cdb.add_credential(
         cred11.cname, cred11.usr, cred11.pwd, cred11.ctype).credential_id
     cdb.update_credential(cred11_id)
     new_usr = "******"
     new_pwd = "new password"
     new_credential = cdb.update_credential(
         cred11_id, new_usr, new_pwd)
     expected_cred = self.CredObj(
         cred11.cname, new_usr, new_pwd, cred11.ctype)
     self._assert_equal(new_credential, expected_cred)
     new_credential = cdb.get_credential(cred11_id)
     self._assert_equal(new_credential, expected_cred)
     with testtools.ExpectedException(c_exc.CredentialNotFound):
         cdb.update_credential(
             "dummyCredentialId", new_usr, new_pwd)
 def put_credential(cred_name, username, password):
     """Set the username and password."""
     cdb.add_credential(TENANT, cred_name, username, password)
 def put_credential(cred_name, username, password):
     """Set the username and password."""
     cdb.add_credential(cred_name, username, password)