summaryrefslogtreecommitdiff
path: root/test.py
blob: dd7ad5e57e25805ce5a9edad821dfd6cd0ae9375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python

import os
import shutil
import subprocess
import string
import tempfile

TROVE_ADMIN_USER = 'richardipsum'

def remote_runcmd(url, command):
    print 'Running: ' + string.join(command)
    subprocess.check_output(['ssh', url] + command)

    # Err find out why this doesn't work when i'm less frazzled
    #subprocess.Popen(['ssh', url] + command, shell=True)

def run_git(args, working_dir):
    #return cliapp.runcmd(['git'] + args, **kwargs)
    print 'args', args
    print 'Running: ', ['git'] + args

    p = subprocess.Popen(['git'] + args, cwd=working_dir)
    return_code = p.wait()

    return return_code

def create_test_project(url, project):
    def t(s):
        return project + '-' + s

    remote_runcmd(url, ['group', 'add', t('managers'), 
        'Managers for ' + project])
    remote_runcmd(url, ['group', 'adduser', t('managers'), TROVE_ADMIN_USER])

    remote_runcmd(url, ['group', 'add', t('admins'), 'Admins for ' + project])
    remote_runcmd(url, ['group', 'addgroup', t('admins'), t('managers')])

    remote_runcmd(url, ['group', 'add', t('writers'), 
        'Users with write access to ' + project])
    remote_runcmd(url, ['group', 'addgroup', t('writers'), t('admins')])

    remote_runcmd(url, ['group', 'add', t('readers'), 
        'Users with read access to ' + project])
    remote_runcmd(url, ['group', 'addgroup', t('readers'), t('writers')])

def create_test_repo(remote_url, project, repo):
    trove_id = 'ct-ri-4' #self.vm_nhame

    remote_runcmd(remote_url, 
        ['create', "%s/%s/%s" % (trove_id, project, repo)])

def run_git_clone(vm_name, project, repo, workspace_dir):
    return run_git(['clone', 'git@%s:%s/%s/%s'
        % (vm_name, vm_name, project, repo)], workspace_dir)

def can_clone(vm_name, project, repo):
    workspace_dir = tempfile.mkdtemp()

    success = run_git_clone(vm_name, project, repo, workspace_dir) == 0

    shutil.rmtree(workspace_dir)

    return success


#def can_push(vm_name, project, repo, workspace_dir):

vm_name = 'ct-ri-4'
workspace_dir = tempfile.mkdtemp()

print 'Created temporary workspace in', workspace_dir

project = 'test-proj'
repo = 'test-repo'
filename = 'test-file'
repodir = os.path.join(workspace_dir, repo)

remote_url = 'git@' + vm_name

create_test_project(remote_url, project)
create_test_repo(remote_url, project, repo)

# We should be able to clone
cloned = can_clone(vm_name, project, repo)
#pushed = can_push()

#with open(os.path.join(workspace_dir, repo, filename), 'w') as f:
#    f.write('A test file')

#run_git(['add', filename], repodir)
#run_git(['commit', '-m', 'Add a test file'], repodir)
#run_git(['push', 'origin', 'master'], repodir)

shutil.rmtree(workspace_dir)