Exemplo n.º 1
0
 def validate_nova_compute_raises_regexp(self, nova_computes, error_msg):
     with self.assertRaisesRegexp(errors.InvalidData, error_msg):
         VmwareAttributesValidator._validate_nova_computes(
             {"editable": self._get_value_vmware_attributes(nova_computes)},
             self.cluster.vmware_attributes
         )
Exemplo n.º 2
0
    def test_update_non_editable_attributes(self):
        metadata = [
            {
                "name": "foo",
                "label": "foo",
                "type": "object",
                "fields": [{
                    "name": "foo_field_name",
                    "label": "foo_field_name",
                }]
            }, {
                "name": "availability_zones",
                "label": "availability_zones",
                "type": "array",
                "fields": [{
                    "name": "az_name",
                    "label": "az_name",
                }, {
                    "name": "nova_computes",
                    "type": "array",
                    "fields": [{
                        "name": "vsphere_cluster",
                        "label": "vsphere_cluster",
                    }, {
                        "name": "target_node",
                        "label": "target_node",
                    }]
                }, {
                    "name": "vcenter_host",
                    "label": "vcenter_host",
                }]
            }
        ]
        db_attributes_value = {
            "availability_zones": [{
                "az_name": "az_1",
                "vcenter_host": "127.0.0.1",
                "nova_computes": [{
                    "vsphere_cluster": "Cluster1",
                    "target_node": {
                        "current": {"id": "node-1"}
                    }
                }]
            }],
            "foo": {
                "foo_field_name": "foo_field_value"
            }
        }
        instance = objects.VmwareAttributes.create(
            {"editable": {"metadata": metadata, "value": db_attributes_value}}
        )

        new_attributes = deepcopy(db_attributes_value)
        new_attributes["foo"] = ["foo_field_name"]
        msg = "Value type of 'foo_field_name' attribute couldn't be changed."
        with self.assertRaisesRegexp(errors.InvalidData, msg):
            VmwareAttributesValidator._validate_updated_attributes(
                {"editable": {"value": new_attributes}},
                instance)

        new_attributes = deepcopy(db_attributes_value)
        new_attributes["foo"]["foo_field_name"] = "new_foo_field_value"
        msg = "Value of 'foo_field_name' attribute couldn't be changed."
        with self.assertRaisesRegexp(errors.InvalidData, msg):
            VmwareAttributesValidator._validate_updated_attributes(
                {"editable": {"value": new_attributes}},
                instance)

        new_attributes = deepcopy(db_attributes_value)
        new_attributes["availability_zones"].append({
            "az_name": "az_2",
            "vcenter_host": "127.0.0.1",
            "nova_computes": []
        })
        msg = "Value of 'availability_zones' attribute couldn't be changed."
        with self.assertRaisesRegexp(errors.InvalidData, msg):
            VmwareAttributesValidator._validate_updated_attributes(
                {"editable": {"value": new_attributes}}, instance)

        new_attributes = deepcopy(db_attributes_value)
        new_attributes["availability_zones"][0]["nova_computes"][0].update(
            {"target_node": {"current": {"id": "node-2"}}}
        )
        msg = "Value of 'target_node' attribute couldn't be changed."
        with self.assertRaisesRegexp(errors.InvalidData, msg):
            VmwareAttributesValidator._validate_updated_attributes(
                {"editable": {"value": new_attributes}}, instance)