class TestRegisterProcessDefinitionIntegration(IonIntegrationTestCase):

    def setUp(self):
        # Start container
        #print 'instantiating container'
        self._start_container()
        #container = Container()
        #print 'starting container'
        #container.start()
        #print 'started container'

        self.container.start_rel_from_url('res/deploy/r2deploy.yml')
        self.RR  = ResourceRegistryServiceClient(node=self.container.node)
        self.DPMS = DataProcessManagementServiceClient(node=self.container.node)

        print 'started services'

#    @unittest.skip('this test just for debugging setup')
#    def test_just_the_setup(self):
#        return

    def test_register_data_process_definition_int(self):

        self.assertRaises(BadRequest, self.DPMS.register_data_process_definition, BASE64_BADPYFILE)

        #test ssh-ability
        cfg_host = CFG.service.data_process_management.process_release_host #'amoeaba.ucsd.edu'
        cfg_user = pwd.getpwuid(os.getuid())[0]

        if "driver_release_user" in CFG.service.data_process_management:
            cfg_user = CFG.service.data_process_management.process_release_user


        remotehost = "%s@%s" % (cfg_user, cfg_host)

        ssh_retval = subprocess.call(["ssh", "-o", "PasswordAuthentication=no",
                                      "-o", "StrictHostKeyChecking=no",
                                      remotehost, "-f", "true"],
                                    stdout=open(os.devnull),
                                    stderr=open(os.devnull))
        
        if 0 != ssh_retval:
            raise unittest.SkipTest("SSH/SCP credentials to %s didn't work" % remotehost)


        remote_url = self.DPMS.register_data_process_definition(BASE64_PYFILE)

        failmsg = ""
        try:
            code = urlopen(remote_url).code
            if 400 <= code:
                failmsg = "HTTP code %s" % code
        except Exception as e:
            failmsg = str(e)

        if failmsg:
            self.fail(("Uploaded succeeded, but fetching '%s' failed with '%s'.") %
                      (remote_url, failmsg))

        return
Example #2
0
class TestRegisterProcessDefinitionIntegration(IonIntegrationTestCase):

    def setUp(self):
        # Start container
        #print 'instantiating container'
        self._start_container()
        #container = Container()
        #print 'starting container'
        #container.start()
        #print 'started container'

        self.container.start_rel_from_url('res/deploy/r2deploy.yml')
        self.RR  = ResourceRegistryServiceClient(node=self.container.node)
        self.DPMS = DataProcessManagementServiceClient(node=self.container.node)

        print 'started services'

#    @unittest.skip('this test just for debugging setup')
#    def test_just_the_setup(self):
#        return

    def test_register_data_process_definition_int(self):

        self.assertRaises(BadRequest, self.DPMS.register_data_process_definition, BASE64_BADPYFILE)

        #test ssh-ability
        cfg_host = CFG.service.data_process_management.process_release_host #'amoeaba.ucsd.edu'
        cfg_user = pwd.getpwuid(os.getuid())[0]

        if "driver_release_user" in CFG.service.data_process_management:
            cfg_user = CFG.service.data_process_management.process_release_user

        cfg_remotepath = CFG.service.data_process_management.process_release_directory

        remotehost = "%s@%s" % (cfg_user, cfg_host)

        ssh_retval = subprocess.call(["ssh", "-o", "PasswordAuthentication=no",
                                      "-o", "StrictHostKeyChecking=no",
                                      remotehost, "-f", "true"],
                                    stdout=open(os.devnull),
                                    stderr=open(os.devnull))
        
        if 0 != ssh_retval:
            raise unittest.SkipTest("SSH/SCP credentials to %s didn't work" % remotehost)


        remote_url = self.DPMS.register_data_process_definition(BASE64_PYFILE)

        def delete_remote_file():
            remote_filename = os.path.basename(urlparse.urlsplit(remote_url)[2])
            remote_file = os.path.join(cfg_remotepath, remote_filename)

            ssh_retval = subprocess.call(["ssh", "-o", "PasswordAuthentication=no",
                                          "-o", "StrictHostKeyChecking=no",
                                          remotehost, "-f", "rm", "-f", remote_file],
                                          stdout=open(os.devnull),
                                          stderr=open(os.devnull))
            if 0 != ssh_retval:
                print "Failed to delete remote file"

        self.addCleanup(delete_remote_file)

        failmsg = ""
        try:
            code = urlopen(remote_url).code
            if 400 <= code:
                failmsg = "HTTP code %s" % code
        except Exception as e:
            failmsg = str(e)

        if failmsg:
            self.fail(("Uploaded succeeded, but fetching '%s' failed with '%s'.") %
                      (remote_url, failmsg))

        return