def test_list_resources(self, mock_volume_list):
        plugin = VolumeProtectablePlugin(self._context)

        mock_volume_list.return_value = \
            [vol_info('123', [], 'name123'), vol_info('456', [], 'name456')]
        self.assertEqual([Resource('OS::Cinder::Volume', '123', 'name123'),
                          Resource('OS::Cinder::Volume', '456', 'name456')],
                         plugin.list_resources(self._context))
    def test_show_resource(self, mock_volume_get):
        plugin = VolumeProtectablePlugin(self._context)

        vol_info = namedtuple('vol_info', ['id', 'name'])
        mock_volume_get.return_value = \
            vol_info(id='123', name='name123')
        self.assertEqual(Resource('OS::Cinder::Volume', '123', 'name123'),
                         plugin.show_resource(self._context, "123"))
 def test_create_client_by_endpoint(self):
     cfg.CONF.set_default('cinder_endpoint',
                          'http://127.0.0.1:8776/v3',
                          'cinder_client')
     plugin = VolumeProtectablePlugin(self._context)
     self.assertEqual('volumev3',
                      plugin._client(self._context).client.service_type)
     self.assertEqual('http://127.0.0.1:8776/v3/abcd',
                      plugin._client(self._context).client.management_url)
    def test_get_server_dependent_resources(self, mock_volume_list):
        plugin = VolumeProtectablePlugin(self._context)

        attached = [{'server_id': 'abcdef', 'name': 'name'}]
        mock_volume_list.return_value = [
            vol_info('123', attached, 'name123'),
            vol_info('456', [], 'name456'),
        ]
        self.assertEqual([Resource('OS::Cinder::Volume', '123', 'name123')],
                         plugin.get_dependent_resources(
                             self._context,
                             Resource("OS::Nova::Server", 'abcdef', 'name')))
    def test_get_project_dependent_resources(self, mock_volume_list):
        project = project_info('abcd', constants.PROJECT_RESOURCE_TYPE,
                               'nameabcd')
        plugin = VolumeProtectablePlugin(self._context)

        volumes = [
            mock.Mock(name='Volume', id='123'),
            mock.Mock(name='Volume', id='456'),
        ]
        setattr(volumes[0], 'os-vol-tenant-attr:tenant_id', 'abcd')
        setattr(volumes[1], 'os-vol-tenant-attr:tenant_id', 'efgh')
        setattr(volumes[0], 'name', 'name123')
        setattr(volumes[1], 'name', 'name456')

        mock_volume_list.return_value = volumes
        self.assertEqual(
            plugin.get_dependent_resources(self._context, project),
            [Resource('OS::Cinder::Volume', '123', 'name123')])
Ejemplo n.º 6
0
 def test_get_resource_type(self):
     plugin = VolumeProtectablePlugin(self._context)
     self.assertEqual("OS::Cinder::Volume", plugin.get_resource_type())
Ejemplo n.º 7
0
 def test_create_client_by_catalog(self):
     plugin = VolumeProtectablePlugin(self._context)
     self.assertEqual('volumev3',
                      plugin._client(self._context).client.service_type)
     self.assertEqual('http://127.0.0.1:8776/v3/abcd',
                      plugin._client(self._context).client.management_url)
Ejemplo n.º 8
0
    def test_get_pod_dependent_resources(self, mock_pod_read, mock_pvc_read,
                                         mock_pv_read, mock_volume_list):
        plugin = VolumeProtectablePlugin(self._context)

        pod = V1Pod(api_version="v1",
                    kind="Pod",
                    metadata=V1ObjectMeta(
                        name="busybox-test",
                        namespace="default",
                        uid="dd8236e1-8c6c-11e7-9b7a-fa163e18e097"),
                    spec=V1PodSpec(volumes=[
                        V1Volume(name="name123",
                                 persistent_volume_claim=(
                                     V1PersistentVolumeClaimVolumeSource(
                                         claim_name="cinder-claim1'")))
                    ],
                                   containers=[]),
                    status=V1PodStatus(phase="Running"))

        pvc = V1PersistentVolumeClaim(
            api_version="v1",
            kind="PersistentVolumeClaim",
            metadata=V1ObjectMeta(name="cinder-claim1",
                                  namespace="default",
                                  uid="fec036b7-9123-11e7-a930-fa163e18e097"),
            spec=V1PersistentVolumeClaimSpec(
                access_modes=["ReadWriteOnce"],
                volume_name="pvc-fec036b7-9123-11e7-a930-fa163e18e097"),
            status=V1PersistentVolumeClaimStatus(phase="Bound"))

        pv = V1PersistentVolume(
            api_version="v1",
            kind="PersistentVolume",
            metadata=V1ObjectMeta(
                name="pvc-fec036b7-9123-11e7-a930-fa163e18e097",
                namespace="None",
                uid="ff43c217-9123-11e7-a930-fa163e18e097"),
            spec=V1PersistentVolumeSpec(cinder=V1CinderVolumeSource(
                fs_type=None,
                read_only=None,
                volume_id="7daedb1d-fc99-4a35-ab1b-b64971271d17")),
            status=V1PersistentVolumeClaimStatus(phase="Bound"))

        volumes = [
            mock.Mock(name='Volume',
                      id='7daedb1d-fc99-4a35-ab1b-b64971271d17',
                      availability_zone='az1'),
            mock.Mock(name='Volume',
                      id='7daedb1d-fc99-4a35-ab1b-b64922441d17',
                      availability_zone='az1'),
        ]
        setattr(volumes[0], 'name', 'name123')
        setattr(volumes[1], 'name', 'name456')

        mock_pod_read.return_value = pod
        mock_pvc_read.return_value = pvc
        mock_pv_read.return_value = pv
        mock_volume_list.return_value = volumes
        self.assertEqual([
            Resource('OS::Cinder::Volume',
                     '7daedb1d-fc99-4a35-ab1b-b64971271d17', 'name123',
                     {'availability_zone': 'az1'})
        ],
                         plugin.get_dependent_resources(
                             self._context,
                             Resource(
                                 id="c88b92a8-e8b4-504c-bad4-343d92061871",
                                 name="default:busybox-test",
                                 type="OS::Kubernetes::Pod")))
 def test_get_parent_resource_types(self):
     plugin = VolumeProtectablePlugin(self._context)
     self.assertItemsEqual(("OS::Nova::Server", "OS::Kubernetes::Pod",
                            "OS::Keystone::Project"),
                           plugin.get_parent_resource_types())
 def test_get_parent_resource_types(self):
     plugin = VolumeProtectablePlugin(self._context)
     self.assertItemsEqual(("OS::Nova::Server", "OS::Keystone::Project"),
                           plugin.get_parent_resource_types())
 def test_get_resource_type(self):
     plugin = VolumeProtectablePlugin(self._context)
     self.assertEqual("OS::Cinder::Volume", plugin.get_resource_type())
 def test_create_client_by_catalog(self):
     plugin = VolumeProtectablePlugin(self._context)
     self.assertEqual('volumev3',
                      plugin._client(self._context).client.service_type)
     self.assertEqual('http://127.0.0.1:8776/v3/abcd',
                      plugin._client(self._context).client.management_url)