Exemplo n.º 1
0
 def test_deploy_ids(self):
     app = handler.Application(self.repo_url, 'master', deploy_id='abc1')
     app.download()
     app.register_kv('node1', 'node2')
     app = handler.Application(self.repo_url, 'master', deploy_id='abc2')
     app.download()
     self.assertEqual(app.previous_deploy_id, 'abc1')
     self.assertEqual(app.deploy_id, 'abc2')
     app.register_kv('node1', 'node2')
     app = handler.Application(self.repo_url, 'master')
     self.assertEqual(app.previous_deploy_id, 'abc1')
     self.assertEqual(app.deploy_id, 'abc2')
Exemplo n.º 2
0
 def test_volumes_from_kv(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     app.register_kv('node1', 'node2')
     self.assertEqual(
         ['foobarmasterddb14_dbdata', 'foobarmasterddb14_wwwdata'],
         sorted(v.name for v in app.volumes_from_kv))
Exemplo n.º 3
0
 def test_log(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     app.caddyfile('wordpress')
     self.assertEqual(
         [
             group for group in app._caddy['wordpress'][0]['body']
             if group[0] == 'log'
         ][0],
         [
             'log', '/', 'stdout',
             '{hostonly} - {>X-Forwarded-For} - {user} [{when}] '
             '\\"{method} {uri} {proto}\\" '
             '{status} {size} '
             '\\"{>Referer}\\" \\"{>User-Agent}\\"'
         ],
     )
     app.caddyfile('wordpress2')
     self.assertEqual(
         [
             group for group in app._caddy['wordpress2'][0]['body']
             if group[0] == 'log'
         ][0],
         ['log', '/', 'stdout', '{hostonly} - {combined}'],
     )
Exemplo n.º 4
0
 def test_check(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     self.assertEqual(None, app.check('node1'))
     # already deployed
     app.register_kv('node1', 'node2')
     app.name = 'new'
     self.assertRaises(ValueError, app.check, 'node1')
Exemplo n.º 5
0
 def test_urls(self):
     app = handler.Application('https://gitlab.example.com/hosting/FooBar2',
                               'master')
     app.download()
     self.assertEqual(
         sorted(app.consul_extra_check_urls(app.services)),
         sorted([
             'http://another.example.com',
             'http://an.example.com',
             'https://an.example.com',
         ]))
Exemplo n.º 6
0
 def test_path(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     app.register_kv('node1', 'node2')
     self.assertTrue(
         app.path.startswith("{}/foobar_master.ddb14@".format(
             handler.DEPLOY)))
     oldapp = handler.Application(self.repo_url, 'master')
     self.assertTrue(
         oldapp.path.startswith("{}/foobar_master.ddb14@".format(
             handler.DEPLOY)))
     newapp = handler.Application(self.repo_url, 'master', deploy_id='abc')
     oldapp = handler.Application(self.repo_url,
                                  'master',
                                  current_deploy_id='abc')
     self.assertEqual(newapp.path,
                      "{}/foobar_master.ddb14-abc".format(handler.DEPLOY))
     newapp.download()
     newapp.register_kv('node2', 'node1')
     self.assertTrue(
         oldapp.path.startswith("{}/foobar_master.ddb14@".format(
             handler.DEPLOY)))
     newapp = handler.Application(self.repo_url, 'master', deploy_id='abc2')
     oldapp = handler.Application(self.repo_url,
                                  'master',
                                  current_deploy_id='abc2')
     self.assertEqual(newapp.path,
                      "{}/foobar_master.ddb14-abc2".format(handler.DEPLOY))
     self.assertEqual(oldapp.path,
                      "{}/foobar_master.ddb14-abc".format(handler.DEPLOY))
Exemplo n.º 7
0
 def test_haproxy_config(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     self.assertEqual(
         {
             "ssh-config-name": {
                 "frontend": {
                     "mode": "tcp",
                     "bind": ["*:2222"]
                 },
                 "backends": [{
                     "name": "ssh-service",
                     "use_backend_option": "",
                     "port": "22",
                     "peer_port": "2222",
                     "ct": "foobarmasterddb14_sshservice_1"
                 }]
             }
         }, app.haproxy(app.services))
Exemplo n.º 8
0
 def test_transparent_headers(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     app.caddyfile('wordpress')
     self.assertEqual([
         group for group in app._caddy['wordpress'][0]['body']
         if group[0] == 'proxy'
     ][0][-1:][0], [
         'websocket',
         'insecure_skip_verify',
         'header_upstream Host {host}',
         'header_upstream X-Real-IP {remote}',
         'header_upstream X-Forwarded-Proto {scheme}',
     ])
     app.caddyfile('wordpress2')
     self.assertEqual([
         group for group in app._caddy['wordpress2'][0]['body']
         if group[0] == 'proxy'
     ][0][-1:][0], [
         'websocket',
         'insecure_skip_verify',
         'transparent',
     ])
Exemplo n.º 9
0
 def test_merge_service_configs_haproxy(self):
     app = handler.Application('https://gitlab.example.com/hosting/FooBar2',
                               'master')
     app.download()
     self.maxDiff = None
     expected = {
         "https-in": {
             "backends": [{
                 "name":
                 "an.example.com",
                 "use_backend_option":
                 "if { req_ssl_sni -i an.example.com"
                 " }",
                 "port":
                 "443",
                 "peer_port":
                 "1443",
                 "server_option":
                 "send_proxy",
                 "ct":
                 "foobar2masterdec69_wordpress_1"
             }]
         },
         "http-in": {
             "backends": [{
                 "name": "an.example.com",
                 "use_backend_option":
                 " if { hdr(host) -i an.example.com }",
                 "port": "80",
                 "peer_port": "80",
                 "ct": "foobar2masterdec69_wordpress_1"
             }, {
                 "name": "another.example.com",
                 "use_backend_option":
                 " if { hdr(host) -i another.example.com }",
                 "port": "80",
                 "peer_port": "80",
                 "ct": "foobar2masterdec69_wordpress2_1"
             }]
         },
         "other-config": {
             "frontend": {
                 "mode":
                 "tcp",
                 "bind": ["*:1111"],
                 "options": [
                     "option socket-stats", "tcp-request inspect-delay 5s",
                     "tcp-request content accept "
                     "if { req_ssl_hello_type 1 }"
                 ]
             },
             "backends": [{
                 "name": "other-config",
                 "use_backend_option":
                 "if { req_ssl_sni -i other.example.com }",
                 "port": "11",
                 "peer_port": "1111",
                 "ct": "foobar2masterdec69_wordpress_1"
             }]
         },
         "ssh-config-name": {
             "frontend": {
                 "mode":
                 "tcp",
                 "bind": ["*:2222", "*:4444"],
                 "options": [
                     "option socket-stats", "tcp-request inspect-delay 5s",
                     "tcp-request content accept "
                     "if { req_ssl_hello_type 1 }", "test", "test2"
                 ]
             },
             "backends": [
                 {
                     "name": "ssh-service-wordpress2",
                     "use_backend_option": "",
                     "port": "22",
                     "peer_port": "2222",
                     "server_option": "send_proxy",
                     "ct": "foobar2masterdec69_wordpress2_1"
                 },
                 {
                     "name": "ssh-service",
                     "use_backend_option": "",
                     "port": "22",
                     "peer_port": "2222",
                     "ct": "foobar2masterdec69_sshservice_1"
                 },
                 {
                     "name": "ssh-service2",
                     "use_backend_option": "",
                     "port": "22",
                     "peer_port": "4444",
                     "ct": "foobar2masterdec69_sshservice2_1"
                 },
             ]
         }
     }
     got = app.haproxy(app.services)
     self.assertEqual(len(got), len(expected))
     self.assertEqual(len(got['ssh-config-name']),
                      len(expected['ssh-config-name']))
     self.assertEqual(len(got['ssh-config-name']['backends']),
                      len(expected['ssh-config-name']['backends']))
     self.assertEqual(
         sorted(got['ssh-config-name']['frontend']['bind']),
         sorted(expected['ssh-config-name']['frontend']['bind']))
     self.assertEqual(
         sorted(got['ssh-config-name']['frontend']['options']),
         sorted(expected['ssh-config-name']['frontend']['options']))
     self.assertEqual(len(got['http-in']), len(expected['http-in']))
Exemplo n.º 10
0
 def test_register_consul(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     self.assertEqual(None, app.register_consul())
Exemplo n.º 11
0
 def test_register_kv(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     self.assertEqual(None, app.register_kv('node1', 'node2'))
Exemplo n.º 12
0
 def test_members(self):
     app = handler.Application(self.repo_url, 'master')
     members = app.members
     self.assertEqual(['node1', 'node2', 'node3'], sorted(members.keys()))
     self.assertEqual(['ip', 'status'], sorted(members['node1'].keys()))
Exemplo n.º 13
0
 def test_volumes(self):
     app = handler.Application(self.repo_url, 'master')
     app.download()
     self.assertEqual(
         ['foobarmasterddb14_dbdata', 'foobarmasterddb14_wwwdata'],
         sorted(v.name for v in app.volumes))
Exemplo n.º 14
0
 def test_application_init(self):
     app = handler.Application(self.repo_url, branch='master')
     self.assertEqual(app.repo_url,
                      'https://gitlab.example.com/hosting/FooBar')
     self.assertEqual(app.name, 'foobar_master.ddb14')