def test_service_instantiation_from_server_role(self):
     definition = {
         'Address': '127.0.0.1',
         'ID': 'Service-blue',
         'Name': 'Service',
         'Port': 12345,
         'Tags': ['version:1.0.0']
     }
     installation_info = {
         'InstallationTimeout': 60,
         'PackageBucket': 'some-bucket',
         'PackageKey': 'some-key'
     }
     service = Service(definition, installation_info)
     self.assertEqual(service.address, '127.0.0.1')
     self.assertEqual(service.deployment_id, None)
     self.assertEqual(service.id, 'Service-blue')
     self.assertEqual(service.installation.get('timeout'), 3600)
     self.assertEqual(service.installation.get('package_bucket'),
                      'some-bucket')
     self.assertEqual(service.installation.get('package_key'), 'some-key')
     self.assertEqual(service.name, 'Service')
     self.assertEqual(service.port, 12345)
     self.assertEqual(service.slice, None)
     self.assertEqual(service.version, '1.0.0')
Esempio n. 2
0
    def test_service_instantiation_failure(self):
        definition = {
            'Address':None,
            'ID':None,
            'Name':None,
            'Tags':[]
        }
        with self.assertRaises(ValueError) as cm:
            Service(definition)
        error = cm.exception
        self.assertEqual(str(error), 'Service address must be specified.')
        definition['Address'] = '127.0.0.1'

        with self.assertRaises(ValueError) as cm:
            Service(definition)
        error = cm.exception
        self.assertEqual(str(error), 'Service ID must be specified.')
Esempio n. 3
0
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.HelpFormatter,
                                     description="""
        Generate a Linux service to handle deployment
        of a given repository
        """)

    parser.add_argument("--repository",
                        required=True,
                        help="The path to the repository directory to handle")

    parser.add_argument("--action",
                        choices=(
                            "status",
                            "start",
                            "stop",
                            "restart",
                        ))

    parser.add_argument("--service-type",
                        choices=("simple", ),
                        default="simple",
                        help="""
        The type of service to create please visit systemd service
        In you choose notify you must create a notify function every
        5s.
        """)

    options = parser.parse_args()
    action = ServiceAction(options.action)
    repository = os.path.normpath(options.repository)
    service = Service(repository, service=options.service_type)

    if action == ServiceAction.STOP:
        service.stop()

    if action == ServiceAction.START:
        service.start()

    if action == ServiceAction.RESTART:
        service.restart()

    if action == ServiceAction.STATUS:
        service.status()
 def test_service_instantiation_from_catalog(self):
     service = Service(self.service_definition)
     self.assertEqual(service.address, '127.0.0.1')
     self.assertEqual(service.deployment_id, '12345')
     self.assertEqual(service.id, 'Service-blue')
     self.assertEqual(service.installation.get('timeout'), 3600)
     self.assertEqual(service.installation.get('package_bucket'), None)
     self.assertEqual(service.installation.get('package_key'), None)
     self.assertEqual(service.name, 'Service')
     self.assertEqual(service.port, 12345)
     self.assertEqual(service.slice, 'blue')
     self.assertEqual(service.version, '1.0.0')
Esempio n. 5
0
 def test_service_coerces_ports_as_ints(self):
     svc_copy = copy.deepcopy(self.service_definition)
     svc_copy['Ports']['blue'] = "87654"
     svc_copy['Ports']['green'] = "32109"
     
     service = Service(svc_copy)
     self.assertEqual(service.address, '127.0.0.1')
     self.assertEqual(service.deployment_id, '12345')
     self.assertEqual(service.id, 'Service-blue')
     self.assertEqual(service.installation.get('timeout'), 3600)
     self.assertEqual(service.installation.get('package_bucket'), None)
     self.assertEqual(service.installation.get('package_key'), None)
     self.assertEqual(service.name, 'Service-blue')
     self.assertEqual(service.slice, 'blue')
     self.assertEqual(service.version, '1.0.0')
     self.assertEqual(service.portsConfig['blue'], 87654)
     self.assertEqual(service.portsConfig['green'], 32109)
Esempio n. 6
0
 def test_overwrite_tag(self):
     service = Service(self.service_definition)
     service.tag('prefix:', 'value1')
     service.tag('prefix:', 'value2')
     self.assertEqual(1, len([tag for tag in service.tags if tag.startswith('prefix:')]))
Esempio n. 7
0
 def test_new_tag(self):
     service = Service(self.service_definition)
     service.tag('prefix:', 'value')
     self.assertTrue('prefix:value' in service.tags)
Esempio n. 8
0
 def test_extract_tag_with_prefix_not_found(self):
     service = Service(self.service_definition)
     self.assertEqual(service._extract_tag_with_prefix('deployment_id:'), '12345')
Esempio n. 9
0
 def test_extract_tag_with_prefix_found(self):
     service = Service(self.service_definition)
     self.assertEqual(service._extract_tag_with_prefix('version:'), '1.0.0')