[apycotlib] fix url used to upload files (related to #4112497)
authorDavid Douard <david.douard@logilab.fr>
Wed, 09 Jul 2014 10:25:30 +0200
changeset 1548 4dbaf65f8cd1
parent 1547 9012705e9076
child 1549 46be4dfc1070
[apycotlib] fix url used to upload files (related to #4112497) also use cnxh logger in TestDataWriter (and add more debug statements) since this former logger is reported in the execution logs (in TestExecution.execution_log).
_apycotlib/writer.py
--- a/_apycotlib/writer.py	Wed Jul 09 11:36:06 2014 +0200
+++ b/_apycotlib/writer.py	Wed Jul 09 10:25:30 2014 +0200
@@ -113,9 +113,6 @@
     def target_eid(self):
         return self._url.rsplit('/',1)[-1]
 
-    def instance_url(self):
-        return '{0}/'.format(self._url.rsplit('/',1)[0])
-
     def start(self):
         pass
 
@@ -157,7 +154,7 @@
                                             data_name=u'log_file.txt',
                                             data_encoding='utf-8')[0]
                 self._log_file_eid = data['eid']
-            self.cnxh.http_post(url=self.instance_url() + 'narval-file-append',
+            self.cnxh.http_post(url=self.cnxh.instance_url + 'narval-file-append',
                                 files=files,
                                 eid=self._log_file_eid)
 
@@ -195,6 +192,7 @@
                              endtime=datetime.now(),)
 
 
+
 class TestDataWriter(BaseDataWriter):
     """Writer intended to report Test level log and result."""
 
@@ -215,25 +213,32 @@
         """mark the current test as closed (with status <status>) and upload
         archive if requested."""
 
+        self.cnxh.debug('End test with status %s' % status)
         self.refresh_log()
         self.cnxh.http_post(self._url, vid='set_attributes',
-                            status = self._unicode(status))
+                            status=self._unicode(status))
         if archivedir:
+            self.cnxh.debug('Archive the apycot temp directory')
             archive = make_archive_name(self.cnxh.instance_id, self.target_eid())
             archivefpath = os.path.join(tempfile.gettempdir(), archive)
             tarball = tarfile.open(archivefpath, ARCHIVE_MODE)
             try:
+                self.cnxh.debug('archive file for %r is %r' % (archive, archivefpath))
+                self.cnxh.debug('** adding %r' % archivedir)
                 tarball.add(archivedir, arcname=os.path.basename(archivedir))
                 tarball.close()
-                files = {'data': ('dummy', open(archivefpath, 'rb'))}
+                self.cnxh.debug('** archive file size: %s' % (os.stat(archivefpath).st_size))
                 data = self.cnxh.http_post(self._url, vid='create_subentity',
                                     __cwetype__='File',
                                     __cwrel__='reverse_execution_archive',
                                     data_name=archive,
                                     data_format=ARCHIVE_MIME_TYPE)[0]
-                self.cnxh.http_post(url=self.instance_url() + 'narval-file-append', files=files, eid=data['eid'])
+                url = self.cnxh.instance_url + 'narval-file-append'
+                files = {'data': ('dummy', open(archivefpath, 'rb'))}
+                self.cnxh.http_post(url=url, files=files, eid=data['eid'])
+                self.cnxh.debug('** archive file %s uploaded' % archive)
             except:
-                self.error('while archiving execution directory', tb=True)
+                self.cnxh.error('while archiving execution directory', tb=True)
             finally:
                 os.unlink(archivefpath)