コード例 #1
0
    def test_app_to_entry_docker(self):
        """Tests convertion of app dictionary to ldap entry."""
        app = {
            '_id': 'xxx',
            'cpu': '100%',
            'memory': '1G',
            'disk': '1G',
            'tickets': [],
            'features': [],
            'endpoints': [],
            'environ': [],
            'traits': ['foo'],
            'services': [
                {
                    'name': 'foo',
                    'image': 'testimage',
                    'useshell': True,
                    'command': 'echo',
                    'restart': {
                        'limit': 3,
                        'interval': 30,
                    },
                },
            ]
        }

        ldap_entry = {
            'app': ['xxx'],
            'cpu': ['100%'],
            'disk': ['1G'],
            'memory': ['1G'],
            'trait': ['foo'],
            # Affinities
            'affinity-level': [],
            'affinity-limit': [],
            # Endpoints
            'endpoint-name': [],
            'endpoint-port': [],
            'endpoint-proto': [],
            'endpoint-type': [],
            # Envvars
            'envvar-name': [],
            'envvar-value': [],
            # Services
            'service-command;tm-service-0': ['echo'],
            'service-image;tm-service-0': ['testimage'],
            'service-name;tm-service-0': ['foo'],
            'service-restart-interval;tm-service-0': ['30'],
            'service-restart-limit;tm-service-0': ['3'],
            'service-useshell;tm-service-0': [True],
        }
        self.assertEqual(ldap_entry, admin.Application(None).to_entry(app))

        app['affinity_limits'] = {}
        app['args'] = []
        app['passthrough'] = []
        app['ephemeral_ports'] = {}

        self.assertEqual(app, admin.Application(None).from_entry(ldap_entry))
コード例 #2
0
ファイル: admin_test.py プロジェクト: ywong587/treadmill
    def test_app_to_entry_and_back(self):
        """Test converting app to/from entry populating default values."""
        app = {
            'cpu':
            '100%',
            'memory':
            '1G',
            'disk':
            '1G',
            'services': [{
                'command': '/a',
                'name': 'a',
                'restart': {
                    'interval': 30,
                    'limit': 3
                }
            }],
            'endpoints': [{
                'name': 'y',
                'port': 2
            }],
            'traits': [],
        }

        expected = {
            'tickets': [],
            'keytabs': [],
            'traits': [],
            'features': [],
            'endpoints': [{
                'name': 'y',
                'port': 2
            }],
            'environ': [],
            'memory':
            '1G',
            'services': [{
                'command': '/a',
                'name': 'a',
                'restart': {
                    'interval': 30,
                    'limit': 3
                }
            }],
            'disk':
            '1G',
            'affinity_limits': {},
            'cpu':
            '100%',
            'passthrough': [],
            'ephemeral_ports': {},
            'args': []
        }

        admin_app = admin.Application(None)
        self.assertEqual(expected,
                         admin_app.from_entry(admin_app.to_entry(app)))

        app['services'][0]['root'] = True
        expected['services'][0]['root'] = True
        self.assertEqual(expected,
                         admin_app.from_entry(admin_app.to_entry(app)))

        app['vring'] = {
            'cells': ['a', 'b'],
            'rules': [{
                'pattern': 'x.y*',
                'endpoints': ['http', 'tcp'],
            }]
        }

        expected['vring'] = {
            'cells': ['a', 'b'],
            'rules': [{
                'pattern': 'x.y*',
                'endpoints': ['http', 'tcp'],
            }]
        }

        self.assertEqual(expected,
                         admin_app.from_entry(admin_app.to_entry(app)))

        app['passthrough'] = ['xxx.x.com', 'yyy.x.com']
        expected['passthrough'] = ['xxx.x.com', 'yyy.x.com']

        self.assertEqual(expected,
                         admin_app.from_entry(admin_app.to_entry(app)))

        app['ephemeral_ports'] = {
            'tcp': 10,
        }
        expected['ephemeral_ports'] = {
            'tcp': 10,
            'udp': 0,
        }

        app['schedule_once'] = True
        expected['schedule_once'] = True

        self.assertEqual(expected,
                         admin_app.from_entry(admin_app.to_entry(app)))

        app['data_retention_timeout'] = '30m'
        expected['data_retention_timeout'] = '30m'

        self.assertEqual(expected,
                         admin_app.from_entry(admin_app.to_entry(app)))

        app['lease'] = '3d'
        expected['lease'] = '3d'

        self.assertEqual(expected,
                         admin_app.from_entry(admin_app.to_entry(app)))
コード例 #3
0
ファイル: admin_test.py プロジェクト: ywong587/treadmill
    def test_app_to_entry(self):
        """Tests convertion of app dictionary to ldap entry."""
        app = {
            '_id':
            'xxx',
            'cpu':
            '100%',
            'memory':
            '1G',
            'disk':
            '1G',
            'tickets': ['a', None, 'b'],
            'keytabs': ['a'],
            'features': [],
            'args': [],
            'environ': [
                {
                    'name': 'BAR',
                    'value': '34567'
                },
                {
                    'name': 'FOO',
                    'value': '12345'
                },
            ],
            'services': [
                {
                    'name': 'a',
                    'command': '/a',
                    'restart': {
                        'limit': 3,
                        'interval': 30,
                    },
                },
                {
                    'name': 'b',
                    'command': '/b',
                },
                {
                    'name': 'c',
                    'command': '/c',
                    'restart': {
                        'limit': 0,
                    },
                },
            ],
            'endpoints': [
                {
                    'name': 'x',
                    'port': 1,
                    'type': 'infra',
                    'proto': 'udp'
                },
                {
                    'name': 'y',
                    'port': 2,
                    'type': 'infra'
                },
            ],
            'affinity_limits': {
                'server': 1,
                'rack': 2
            },
            'passthrough': [],
            'ephemeral_ports': {
                'tcp': 5,
                'udp': 10,
            },
            'shared_ip':
            True,
            'shared_network':
            True,
            'traits': ['foo'],
        }

        ldap_entry = {
            'app': ['xxx'],
            'cpu': ['100%'],
            'memory': ['1G'],
            'disk': ['1G'],
            'ticket': ['a', 'b'],
            'keytab': ['a'],
            'trait': ['foo'],
            'service-name;tm-service-0': ['a'],
            'service-name;tm-service-1': ['b'],
            'service-name;tm-service-2': ['c'],
            'service-restart-limit;tm-service-0': ['3'],
            'service-restart-limit;tm-service-1': ['5'],
            'service-restart-limit;tm-service-2': ['0'],
            'service-restart-interval;tm-service-0': ['30'],
            'service-restart-interval;tm-service-1': ['60'],
            'service-restart-interval;tm-service-2': ['60'],
            'service-command;tm-service-0': ['/a'],
            'service-command;tm-service-1': ['/b'],
            'service-command;tm-service-2': ['/c'],
            'endpoint-name;tm-endpoint-0': ['x'],
            'endpoint-name;tm-endpoint-1': ['y'],
            'endpoint-port;tm-endpoint-0': ['1'],
            'endpoint-port;tm-endpoint-1': ['2'],
            'endpoint-type;tm-endpoint-0': ['infra'],
            'endpoint-type;tm-endpoint-1': ['infra'],
            'endpoint-proto;tm-endpoint-0': ['udp'],
            'envvar-name;tm-envvar-0': ['BAR'],
            'envvar-value;tm-envvar-0': ['34567'],
            'envvar-name;tm-envvar-1': ['FOO'],
            'envvar-value;tm-envvar-1': ['12345'],
            'affinity-level;tm-affinity-0': ['rack'],
            'affinity-limit;tm-affinity-0': ['2'],
            'affinity-level;tm-affinity-1': ['server'],
            'affinity-limit;tm-affinity-1': ['1'],
            'ephemeral-ports-tcp': ['5'],
            'ephemeral-ports-udp': ['10'],
            'shared-ip': [True],
            'shared-network': [True]
        }

        # TODO this logs "Expected [<class 'str'>], got ['a', None, 'b']"
        # see treadmill.admin:_dict_2_entry
        self.assertEqual(ldap_entry, admin.Application(None).to_entry(app))

        # When converting to entry, None are skipped, and unicode is converted
        # to str.
        #
        # Adjust app['tickets'] accordingly.
        app['tickets'] = ['a', 'b']
        # Account for default restart values
        app['services'][1]['restart'] = {'limit': 5, 'interval': 60}
        app['services'][2]['restart']['interval'] = 60

        self.assertEqual(app, admin.Application(None).from_entry(ldap_entry))