Example #1
0
    def test_rename(self):
        an_container = container.Container(
            name='an-container', _client=self.client)

        an_container.rename('an-renamed-container', wait=True)

        self.assertEqual('an-renamed-container', an_container.name)
Example #2
0
    def test_fetch(self):
        """A sync updates the properties of a container."""
        an_container = container.Container(self.client, name='an-container')

        an_container.sync()

        self.assertTrue(an_container.ephemeral)
Example #3
0
    def test_delete(self):
        """A container is deleted."""
        # XXX: rockstar (21 May 2016) - This just executes
        # a code path. There should be an assertion here, but
        # it's not clear how to assert that, just yet.
        an_container = container.Container(self.client, name='an-container')

        an_container.delete(wait=True)
Example #4
0
    def test_fetch(self):
        """A fetch updates the properties of a container."""
        an_container = container.Container(
            name='an-container', _client=self.client)

        an_container.fetch()

        self.assertTrue(an_container.ephemeral)
Example #5
0
    def test_reload(self):
        """A reload updates the properties of a container."""
        an_container = container.Container(name='an-container',
                                           _client=self.client)

        an_container.reload()

        self.assertTrue(an_container.ephemeral)
Example #6
0
    def test_migrate(self):
        """A container is migrated."""
        from pylxd.client import Client

        client2 = Client(endpoint='http://pylxd2.test')
        an_container = container.Container(self.client, name='an-container')

        an_migrated_container = an_container.migrate(client2)

        self.assertEqual('an-container', an_migrated_container.name)
        self.assertEqual(client2, an_migrated_container.client)
Example #7
0
    def test_execute(self, _CommandWebsocketClient, _StdinWebsocket):
        """A command is executed on a container."""
        fake_websocket = mock.Mock()
        fake_websocket.data = 'test\n'
        _StdinWebsocket.return_value = fake_websocket
        _CommandWebsocketClient.return_value = fake_websocket

        an_container = container.Container(self.client, name='an-container')

        stdout, _ = an_container.execute(['echo', 'test'])

        self.assertEqual('test\n', stdout)
Example #8
0
    def test_update(self):
        """A container is updated."""
        an_container = container.Container(self.client, name='an-container')
        an_container.architecture = 1
        an_container.config = {}
        an_container.created_at = 1
        an_container.devices = {}
        an_container.ephemeral = 1
        an_container.expanded_config = {}
        an_container.expanded_devices = {}
        an_container.profiles = 1
        an_container.status = 1

        an_container.save(wait=True)

        self.assertTrue(an_container.ephemeral)
Example #9
0
    def test_fetch_error(self):
        """LXDAPIException is raised on error."""
        def not_found(request, context):
            context.status_code = 500
            return json.dumps({
                'type': 'error',
                'error': 'An bad error',
                'error_code': 500})
        self.add_rule({
            'text': not_found,
            'method': 'GET',
            'url': r'^http://pylxd.test/1.0/containers/an-missing-container$',  # NOQA
        })

        an_container = container.Container(
            name='an-missing-container', _client=self.client)

        self.assertRaises(exceptions.LXDAPIException, an_container.fetch)
Example #10
0
    def test_fetch_not_found(self):
        """NotFound is raised on a 404 for updating container."""
        def not_found(request, context):
            context.status_code = 404
            return json.dumps({
                'type': 'error',
                'error': 'Not found',
                'error_code': 404})
        self.add_rule({
            'text': not_found,
            'method': 'GET',
            'url': r'^http://pylxd.test/1.0/containers/an-missing-container$',  # NOQA
        })

        an_container = container.Container(
            name='an-missing-container', _client=self.client)

        self.assertRaises(exceptions.NotFound, an_container.fetch)
Example #11
0
    def test_reload_not_found(self):
        """NameError is raised on a 404 for updating container."""
        def not_found(request, context):
            context.status_code = 404
            return json.dumps({
                'type': 'error',
                'error': 'Not found',
                'error_code': 404
            })

        self.add_rule({
            'text':
            not_found,
            'method':
            'GET',
            'url':
            r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)$',  # NOQA
        })

        an_container = container.Container(name='an-missing-container',
                                           _client=self.client)

        self.assertRaises(NameError, an_container.reload)
Example #12
0
    def test_execute_string(self):
        """A command passed as string raises a TypeError."""
        an_container = container.Container(self.client, name='an-container')

        self.assertRaises(TypeError, an_container.execute, 'apt-get update')