Exemplo n.º 1
0
    def test_publish(self):
        """Snapshots can be published."""
        self.add_rule({
            'text':
            json.dumps({
                'type': 'sync',
                'metadata': {
                    'id': 'operation-abc',
                    'metadata': {
                        'fingerprint': ('e3b0c44298fc1c149afbf4c8996fb92427'
                                        'ae41e4649b934ca495991b7852b855')
                    }
                }
            }),
            'method':
            'GET',
            'url':
            r'^http://pylxd.test/1.0/operations/operation-abc$',
        })

        snapshot = models.Snapshot(self.client,
                                   container=self.container,
                                   name='an-snapshot')

        image = snapshot.publish(wait=True)

        self.assertEqual(
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
            image.fingerprint)
Exemplo n.º 2
0
    def test_publish(self):
        """Snapshots can be published."""
        self.add_rule(
            {
                "text": json.dumps(
                    {
                        "type": "sync",
                        "metadata": {
                            "id": "operation-abc",
                            "metadata": {
                                "fingerprint": (
                                    "e3b0c44298fc1c149afbf4c8996fb92427"
                                    "ae41e4649b934ca495991b7852b855"
                                )
                            },
                        },
                    }
                ),
                "method": "GET",
                "url": r"^http://pylxd.test/1.0/operations/operation-abc$",
            }
        )

        snapshot = models.Snapshot(
            self.client, instance=self.instance, name="an-snapshot"
        )

        image = snapshot.publish(wait=True)

        self.assertEqual(
            "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            image.fingerprint,
        )
Exemplo n.º 3
0
    def test_delete(self):
        """A snapshot is deleted."""
        snapshot = models.Snapshot(self.client,
                                   container=self.container,
                                   name='an-snapshot')

        snapshot.delete(wait=True)
Exemplo n.º 4
0
    def test_delete_failure(self):
        """If the response indicates delete failure, raise an exception."""

        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": "DELETE",
                "url": (
                    r"^http://pylxd.test/1.0/instances/"
                    "an-instance/snapshots/an-snapshot$"
                ),
            }
        )

        snapshot = models.Snapshot(
            self.client, instance=self.instance, name="an-snapshot"
        )

        self.assertRaises(exceptions.LXDAPIException, snapshot.delete)
Exemplo n.º 5
0
    def test_delete(self):
        """A snapshot is deleted."""
        snapshot = models.Snapshot(
            self.client, instance=self.instance, name="an-snapshot"
        )

        snapshot.delete(wait=True)
Exemplo n.º 6
0
    def test_rename(self):
        """A snapshot is renamed."""
        snapshot = models.Snapshot(self.client,
                                   container=self.container,
                                   name='an-snapshot')

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

        self.assertEqual('an-renamed-snapshot', snapshot.name)
Exemplo n.º 7
0
    def test_rename(self):
        """A snapshot is renamed."""
        snapshot = models.Snapshot(
            self.client, instance=self.instance, name="an-snapshot"
        )

        snapshot.rename("an-renamed-snapshot", wait=True)

        self.assertEqual("an-renamed-snapshot", snapshot.name)
Exemplo n.º 8
0
    def test_delete_failure(self):
        """If the response indicates delete failure, raise an exception."""
        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': 'DELETE',
            'url': r'^http://pylxd.test/1.0/containers/an-container/snapshots/an-snapshot$',  # NOQA
        })

        snapshot = models.Snapshot(
            self.client, container=self.container,
            name='an-snapshot')

        self.assertRaises(exceptions.LXDAPIException, snapshot.delete)
Exemplo n.º 9
0
 def test_restore_snapshot(self):
     """Snapshots can be restored from the snapshot object"""
     snapshot = models.Snapshot(self.client,
                                container=self.container,
                                name='an-snapshot')
     snapshot.restore(wait=True)
Exemplo n.º 10
0
 def test_restore_snapshot(self):
     """Snapshots can be restored from the snapshot object"""
     snapshot = models.Snapshot(
         self.client, instance=self.instance, name="an-snapshot"
     )
     snapshot.restore(wait=True)