From 31349c6700d418ace3aa3349a3fd74e81549ef2a Mon Sep 17 00:00:00 2001 From: gakin <gakin> Date: Tue, 8 Nov 2016 14:18:24 +0000 Subject: [PATCH] SSDM-4318: test_openbis_sync : compare datasource and harvester graphs, assert + minor change to harvester config. SVN: 37288 --- .../harvester_config/harvester-config.txt | 2 +- integration-tests/test_openbis_sync.py | 50 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/integration-tests/templates/test_openbis_sync/harvester_config/harvester-config.txt b/integration-tests/templates/test_openbis_sync/harvester_config/harvester-config.txt index 3f33145ff6a..827e641b14b 100644 --- a/integration-tests/templates/test_openbis_sync/harvester_config/harvester-config.txt +++ b/integration-tests/templates/test_openbis_sync/harvester_config/harvester-config.txt @@ -5,7 +5,7 @@ data-source-openbis-url = https://localhost:8443/openbis/openbis data-source-dss-url = https://localhost:8444/datastore_server #data-source-spaces = SRC #harvester-spaces = DST1 -data-source-alias = DS43 +data-source-alias = DS1 data-source-auth-realm = OAI-PMH data-source-auth-user = harvester1 data-source-auth-pass = 123 diff --git a/integration-tests/test_openbis_sync.py b/integration-tests/test_openbis_sync.py index d5d2a6e9f6a..a3a279eb3b0 100755 --- a/integration-tests/test_openbis_sync.py +++ b/integration-tests/test_openbis_sync.py @@ -47,6 +47,7 @@ class TestCase(systemtest.testcase.TestCase): openbis2.createTestDatabase('imaging') openbis2.createTestDatabase('proteomics') + def executeInDevMode(self): openbis1 = self.createOpenbisController(instanceName = 'openbis1', dropDatabases=False) openbis1.setDummyAuthentication() @@ -59,7 +60,7 @@ class TestCase(systemtest.testcase.TestCase): openbis1.setDataStoreServerProperty("host-address", "https://localhost") openbis1.allUp() - #openbis1.dropAndWait("ENTITY_REGISTRATION", "openbis-sync-entity-reg") + openbis1.dropAndWait("ENTITY_REGISTRATION", "openbis-sync-entity-reg") openbis2_port = '8445' openbis2_dss_port = '8446' @@ -83,11 +84,49 @@ class TestCase(systemtest.testcase.TestCase): monitor.addNotificationCondition(util.RegexCondition('OPERATION.DataSetRegistrationTask')) monitor.waitUntilEvent(util.RegexCondition('OPERATION.DataSetRegistrationTask - Saving the timestamp of sync start to file')) - datasource_graph = self.getResourceListForComparison(openbis2_dss_port, 'harvester1', '123') - harvester_graph = self.getResourceListForComparison('8443', 'testuser', '123') + '''read entity graph from datasource''' + datasource_graph_response = self.getResourceListForComparison('8444', 'harvester1', '123') + file1 = os.path.join(destination, "datasource_graph.txt") + self.writeResponseToFile(datasource_graph_response, file1) + content1 = self.readLinesFromFile(file1) + content1.sort() + + '''read entity graph from harvester''' + harvester_graph_response = self.getResourceListForComparison(openbis2_dss_port, 'testuser1', '123') + file2 = os.path.join(destination, "harvester_graph.txt") + self.writeResponseToFile(harvester_graph_response, file2) + content2 = self.readLinesFromFile(file2) + content2.sort() + + '''compare the two. If the only different is in space labels then we are good.''' + diff_array = self.diff(set(content1), set(content2)) + same = True + with open(os.path.join(destination, "diff.txt"), 'wb') as output: + for item in diff_array: + output.write("%s\n" % item) + if item.startswith("label") == False: + same = False + + if same == False: + self.fail("The entity graphs on datasource and harvester are not equal.See %s for details" % os.path.join(destination, "diff.txt")) + + def readLinesFromFile(self, file): + with open(file, 'rb') as output: + content = output.readlines() + return content + + def writeResponseToFile(self, datasource_graph_response, file1): + with open(file1, 'wb') as output: + output.write(datasource_graph_response.read()) + return output + + def diff(self, first, second): + first = set(first) + second = set(second) + return [item for item in first if item not in second] def getResourceListForComparison(self, dss_port, user, password): - url = "https://localhost:%s/datastore_server/re-sync?verb=resourcelist.xml"%dss_port + url = "https://localhost:%s/datastore_server/re-sync?verb=resourcelist.xml" % dss_port request = urllib2.Request(url) request.add_header('Accept', 'application/json') request.add_header("Content-type", "application/x-www-form-urlencoded") @@ -95,8 +134,7 @@ class TestCase(systemtest.testcase.TestCase): request.add_header("Authorization", "Basic %s" % base64string) data = urllib.urlencode({'mode' : 'test'}) response = urllib2.urlopen(request, data) - util.printAndFlush(response.read()) - return + return response def installPlugin(self, openbisController, plugin_name): repository = GitLabArtifactRepository(self.artifactRepository.localRepositoryFolder) -- GitLab