diff --git a/libs/client/MockMiddleTierAdmin.cpp b/libs/client/MockMiddleTierAdmin.cpp index c5db64f0b1f42ac7105277e9a7b7b65166201e59..aefc2a7fd55ed8ee076f18e8964de35e9ff8bce7 100644 --- a/libs/client/MockMiddleTierAdmin.cpp +++ b/libs/client/MockMiddleTierAdmin.cpp @@ -354,6 +354,29 @@ void cta::MockMiddleTierAdmin::createTape( const std::string &tapePoolName, const uint64_t capacityInBytes, const std::string &comment) { + checkTapeDoesNotAlreadyExist(vid); + Tape tape( + vid, + logicalLibraryName, + tapePoolName, + capacityInBytes, + requester.user, + comment); + m_db.tapes[vid] = tape; +} + +//------------------------------------------------------------------------------ +// checkTapeDoesNotAlreadyExist +//------------------------------------------------------------------------------ +void cta::MockMiddleTierAdmin::checkTapeDoesNotAlreadyExist( + const std::string &vid) const { + std::map<std::string, Tape>::const_iterator itor = + m_db.tapes.find(vid); + if(itor != m_db.tapes.end()) { + std::ostringstream message; + message << "Tape with vid " << vid << " already exists"; + throw(Exception(message.str())); + } } //------------------------------------------------------------------------------ @@ -362,6 +385,19 @@ void cta::MockMiddleTierAdmin::createTape( void cta::MockMiddleTierAdmin::deleteTape( const SecurityIdentity &requester, const std::string &vid) { + for(std::map<std::string, Tape>::iterator itor = m_db.tapes.begin(); + itor != m_db.tapes.end(); itor++) { + if(vid == itor->first) { + m_db.tapes.erase(itor); + return; + } + } + + // Reaching this point means the tape to be deleted does not + // exist + std::ostringstream message; + message << "Tape iwith volume identifier " << vid << " does not exist"; + throw Exception(message.str()); } //------------------------------------------------------------------------------ @@ -370,5 +406,11 @@ void cta::MockMiddleTierAdmin::deleteTape( std::list<cta::Tape> cta::MockMiddleTierAdmin::getTapes( const SecurityIdentity &requester) const { std::list<cta::Tape> tapes; + + for(std::map<std::string, Tape>::const_iterator itor = m_db.tapes.begin(); + itor != m_db.tapes.end(); itor++) { + tapes.push_back(itor->second); + } + return tapes; } diff --git a/libs/client/MockMiddleTierAdmin.hpp b/libs/client/MockMiddleTierAdmin.hpp index 6ef869da3f3a7ebfd7f5fefda362ab78b2f7852a..285d834fcfb3327f2822ac9c453eef989cf0bb70 100644 --- a/libs/client/MockMiddleTierAdmin.hpp +++ b/libs/client/MockMiddleTierAdmin.hpp @@ -349,6 +349,13 @@ protected: */ void checkLogicalLibraryDoesNotAlreadyExist(const std::string &name) const; + /** + * Throws an exception if the specified tape already exists. + * + * @param vid The volume identifier of the tape. + */ + void checkTapeDoesNotAlreadyExist(const std::string &vid) const; + /** * The database of the mock middle-tier. */ diff --git a/libs/client/MockMiddleTierAdminTest.cpp b/libs/client/MockMiddleTierAdminTest.cpp index fb28241e2b7344d73a1d4763e54d8f5786fdb660..9b3d3e206f1d5bccf8fc06ff9caf5eec0ba97fe6 100644 --- a/libs/client/MockMiddleTierAdminTest.cpp +++ b/libs/client/MockMiddleTierAdminTest.cpp @@ -1320,7 +1320,7 @@ TEST_F(cta_client_MockMiddleTierAdminTest, deleteTape_existing) { ASSERT_THROW(adminApi.createTape(requester, vid, libraryName, poolName, capacityInBytes, tapeComment), std::exception); - ASSERT_NO_THROW(adminApi.deleteLogicalLibrary(requester, vid)); + ASSERT_NO_THROW(adminApi.deleteTape(requester, vid)); { std::list<Tape> tapes; diff --git a/libs/client/MockMiddleTierDatabase.hpp b/libs/client/MockMiddleTierDatabase.hpp index b4b98f8a72ab7934d38a60fc4789e19974d56562..0643f6e79700d542236a1ab68bc20c8da6ec15fd 100644 --- a/libs/client/MockMiddleTierDatabase.hpp +++ b/libs/client/MockMiddleTierDatabase.hpp @@ -8,6 +8,7 @@ #include "MiddleTierUser.hpp" #include "MigrationRoutes.hpp" #include "StorageClass.hpp" +#include "Tape.hpp" #include <stdint.h> #include <string> @@ -69,6 +70,11 @@ public: */ std::map<std::string, LogicalLibrary> libraries; + /** + * Mapping from volume identiifer to tape. + */ + std::map<std::string, Tape> tapes; + }; // class MockMiddleTierDatabase } // namespace cta