def test_script(self): branches = [ self.factory.makeProductBranch(), self.factory.makePersonalBranch(), self.factory.makePackageBranch(), ] input_lines = ["/%s/.bzr/README" % branch.unique_name for branch in branches] + [ "/%s/changes" % branch.unique_name for branch in branches ] expected_lines = [ "file:///var/tmp/bazaar.launchpad.dev/mirrors/%s/.bzr/README" % branch_id_to_path(branch.id) for branch in branches ] + ["http://localhost:8080/%s/changes" % branch.unique_name for branch in branches] transaction.commit() script_file = os.path.join(config.root, "scripts", "branch-rewrite.py") proc = subprocess.Popen( [script_file], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0 ) output_lines = [] # For each complete line of input, the script should, without # buffering, write a complete line of output. for input_line in input_lines: proc.stdin.write(input_line + "\n") output_lines.append(nonblocking_readline(proc.stdout, 60).rstrip("\n")) # If we create a new branch after the branch-rewrite.py script has # connected to the database, or edit a branch name that has already # been rewritten, both are rewritten successfully. new_branch = self.factory.makeAnyBranch() edited_branch = removeSecurityProxy(branches[0]) edited_branch.name = self.factory.getUniqueString() transaction.commit() new_branch_input = "/%s/.bzr/README" % new_branch.unique_name expected_lines.append( "file:///var/tmp/bazaar.launchpad.dev/mirrors/%s/.bzr/README" % branch_id_to_path(new_branch.id) ) proc.stdin.write(new_branch_input + "\n") output_lines.append(nonblocking_readline(proc.stdout, 60).rstrip("\n")) edited_branch_input = "/%s/.bzr/README" % edited_branch.unique_name expected_lines.append( "file:///var/tmp/bazaar.launchpad.dev/mirrors/%s/.bzr/README" % branch_id_to_path(edited_branch.id) ) proc.stdin.write(edited_branch_input + "\n") output_lines.append(nonblocking_readline(proc.stdout, 60).rstrip("\n")) os.kill(proc.pid, signal.SIGINT) err = proc.stderr.read() # The script produces logging output, but not to stderr. self.assertEqual("", err) self.assertEqual(expected_lines, output_lines)
def request(self, query): self.rewriter_proc.stdin.write(query + "\n") self.rewriter_proc.stdin.flush() # 60 second timeout as we might need to wait for the script to # finish starting up. result = nonblocking_readline(self.rewriter_proc.stdout, 60) if result.endswith("\n"): return result[:-1] self.fail("Incomplete line or no result retrieved from subprocess: %s" % repr(result.getvalue()))
def request(self, query): self.rewriter_proc.stdin.write(query + '\n') self.rewriter_proc.stdin.flush() # 60 second timeout as we might need to wait for the script to # finish starting up. result = nonblocking_readline(self.rewriter_proc.stdout, 60) if result.endswith('\n'): return result[:-1] self.fail( "Incomplete line or no result retrieved from subprocess: %s" % repr(result.getvalue()))
def test_script(self): # The .bzr subdirectory of all public branch types gets mapped # to the internal by-ID branch store, but everything else, and # all private branch requests, go through to loggerhead. bs = [ self.factory.makeProductBranch(), self.factory.makePersonalBranch(), self.factory.makePackageBranch() ] privbranch = removeSecurityProxy( self.factory.makeProductBranch( information_type=InformationType.USERDATA)) allbs = bs + [privbranch] input_lines = ( ["/%s/.bzr/README" % branch.unique_name for branch in allbs] + ["/%s/changes" % branch.unique_name for branch in allbs]) expected_lines = ( [ 'file:///var/tmp/bazaar.launchpad.dev/mirrors/%s/.bzr/README' % branch_id_to_path(branch.id) for branch in bs ] + ['http://localhost:8080/%s/.bzr/README' % privbranch.unique_name] + ['http://localhost:8080/%s/changes' % b.unique_name for b in bs] + ['http://localhost:8080/%s/changes' % privbranch.unique_name]) transaction.commit() script_file = os.path.join(config.root, 'scripts', 'branch-rewrite.py') proc = subprocess.Popen([script_file], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) output_lines = [] # For each complete line of input, the script should, without # buffering, write a complete line of output. for input_line in input_lines: proc.stdin.write(input_line + '\n') output_lines.append( nonblocking_readline(proc.stdout, 60).rstrip('\n')) # If we create a new branch after the branch-rewrite.py script has # connected to the database, or edit a branch name that has already # been rewritten, both are rewritten successfully. new_branch = self.factory.makeAnyBranch() edited_branch = removeSecurityProxy(bs[0]) edited_branch.name = self.factory.getUniqueString() transaction.commit() new_branch_input = '/%s/.bzr/README' % new_branch.unique_name expected_lines.append( 'file:///var/tmp/bazaar.launchpad.dev/mirrors/%s/.bzr/README' % branch_id_to_path(new_branch.id)) proc.stdin.write(new_branch_input + '\n') output_lines.append(nonblocking_readline(proc.stdout, 60).rstrip('\n')) edited_branch_input = '/%s/.bzr/README' % edited_branch.unique_name expected_lines.append( 'file:///var/tmp/bazaar.launchpad.dev/mirrors/%s/.bzr/README' % branch_id_to_path(edited_branch.id)) proc.stdin.write(edited_branch_input + '\n') output_lines.append(nonblocking_readline(proc.stdout, 60).rstrip('\n')) os.kill(proc.pid, signal.SIGINT) err = proc.stderr.read() # The script produces logging output, but not to stderr. self.assertEqual('', err) self.assertEqual(expected_lines, output_lines)