Bladeren bron

Add support for links, rework tests.

tags/v0.1.1
Chris Smith 7 jaren geleden
bovenliggende
commit
bea0f0c33c
4 gewijzigde bestanden met toevoegingen van 57 en 23 verwijderingen
  1. 2
    1
      README.md
  2. 14
    0
      docker-rerun
  3. 0
    1
      requirements.txt
  4. 41
    21
      test.py

+ 2
- 1
README.md Bestand weergeven

29
     * Commands (trailing arguments)
29
     * Commands (trailing arguments)
30
     * Environment variables (-e/--env)
30
     * Environment variables (-e/--env)
31
     * Labels (-l/--label)
31
     * Labels (-l/--label)
32
+    * Links (--link)
32
     * Names (--name)
33
     * Names (--name)
33
     * Networks (--net)
34
     * Networks (--net)
34
     * Port publications (-p)
35
     * Port publications (-p)
40
 
41
 
41
 Many other command line arguments:
42
 Many other command line arguments:
42
 
43
 
43
-    * Linking and aliases
44
+    * Network aliases
44
     * Permissions and policies
45
     * Permissions and policies
45
     * Advanced networking options
46
     * Advanced networking options
46
 
47
 

+ 14
- 0
docker-rerun Bestand weergeven

135
             container.args.append('--label=%s' % key)
135
             container.args.append('--label=%s' % key)
136
 
136
 
137
 
137
 
138
+def handle_links(container):
139
+    """Copies the link (--link) arguments."""
140
+    name = container.info['Name']
141
+    links = container.info['HostConfig']['Links'] or []
142
+    for link in links:
143
+        (target, alias) = link.split(':')
144
+        target = target[1:]
145
+        alias = alias[len(name) + 1:]
146
+        if alias == target:
147
+            container.args.append('--link=%s' % target)
148
+        else:
149
+            container.args.append('--link=%s:%s' % (target, alias))
150
+
151
+
138
 def handle_name(container):
152
 def handle_name(container):
139
     """Copies the name (--name) argument."""
153
     """Copies the name (--name) argument."""
140
     # Trim the leading / off the name. They're equivalent from docker's point
154
     # Trim the leading / off the name. They're equivalent from docker's point

+ 0
- 1
requirements.txt Bestand weergeven

1
 nose
1
 nose
2
-nose_parameterized
3
 pylint
2
 pylint
4
 
3
 

+ 41
- 21
test.py Bestand weergeven

1
 #!/usr/bin/python3
1
 #!/usr/bin/python3
2
 
2
 
3
 import subprocess
3
 import subprocess
4
-from nose_parameterized import parameterized
4
+from nose.tools import with_setup
5
 
5
 
6
 
6
 
7
 def _run(cmd):
7
 def _run(cmd):
10
                     stderr=subprocess.DEVNULL)
10
                     stderr=subprocess.DEVNULL)
11
 
11
 
12
 
12
 
13
-@parameterized([
14
-    ['docker', 'run', '--name=test123', '-d', 'hello-world'],
15
-    ['docker', 'run', '--name=test123', '-d', 'hello-world:latest'],
16
-    ['docker', 'run', '--name=test123', '-d', 'hello-world', '/hello', 'world...'],
17
-    ['docker', 'run', '--env=PATH=/root', '--env=Z=X', '--name=test123', '-d', 'hello-world'],
18
-    ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world'],
19
-    ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world'],
20
-    ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world'],
21
-    ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world'],
22
-    ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world'],
23
-    ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world'],
24
-    ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar'],
25
-    ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world'],
26
-    ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world'],
27
-    ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world'],
28
-    ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world'],
29
-])
30
-def test_command_matches(*command):
13
+def setup():
14
+    _run(['docker', 'run', '--name=testA', '-d', 'hello-world'])
15
+    _run(['docker', 'run', '--name=testB', '-d', 'hello-world'])
16
+
17
+
18
+def teardown():
19
+    _run(['docker', 'rm', '-f', 'testA'])
20
+    _run(['docker', 'rm', '-f', 'testB'])
21
+
22
+
23
+def setup_each():
24
+    _run(['docker', 'rm', '-f', 'test123'])
25
+
26
+
27
+def teardown_each():
31
     _run(['docker', 'rm', '-f', 'test123'])
28
     _run(['docker', 'rm', '-f', 'test123'])
29
+
30
+
31
+@with_setup(setup, teardown)
32
+def test_command_matches():
33
+    yield check, ['docker', 'run', '--name=test123', '-d', 'hello-world']
34
+    yield check, ['docker', 'run', '--name=test123', '-d', 'hello-world:latest']
35
+    yield check, ['docker', 'run', '--name=test123', '-d', 'hello-world', '/hello', 'world...']
36
+    yield check, ['docker', 'run', '--env=PATH=/root', '--env=Z=X', '--name=test123', '-d', 'hello-world']
37
+    yield check, ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world']
38
+    yield check, ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world']
39
+    yield check, ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world']
40
+    yield check, ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world']
41
+    yield check, ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world']
42
+    yield check, ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world']
43
+    yield check, ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar']
44
+    yield check, ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world']
45
+    yield check, ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world']
46
+    yield check, ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world']
47
+    yield check, ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world']
48
+    yield check, ['docker', 'run', '--link=testA:bar', '--link=testB', '--name=test123', '-d', 'hello-world']
49
+
50
+
51
+@with_setup(setup_each, teardown_each)
52
+def check(command):
32
     _run(command)
53
     _run(command)
33
     output = subprocess.check_output(['./docker-rerun', '--dry-run', 'test123'])
54
     output = subprocess.check_output(['./docker-rerun', '--dry-run', 'test123'])
34
     output = output.decode('utf-8').strip().splitlines()
55
     output = output.decode('utf-8').strip().splitlines()
35
-    assert output[3] == ' '.join(command)
36
-    _run(['docker', 'rm', '-f', 'test123'])
56
+    assert output[3] == ' '.join(command), 'Expected "%s" but got "%s"' % (' '.join(command), output[3])
37
 
57
 

Laden…
Annuleren
Opslaan