Ask Your Question
1

I found the flavor, and have returned, but why the function still raise Exception? and strange is I can not catch it .

asked 2017-11-23 04:48:43 -0500

liaodalin19903 gravatar image

I finded the flavor, and have returned, but why the function still raise Exception? and strange is I can not catch it .

I have a retrieveFlavor function.

    try:
        vcpus_id = data["vcpus"]
        vcpus = CPUType.objects.get(id=vcpus_id).name[:-1]
        flavor = retrieveFlavor(vcpu=str(vcpus),
                                ram=str(data["ram"]),
                                disk=str(data["disk_os"]["disk_size"]),
                                rxtx_factor=str(data["bandwidth"]))
    except Exception as e:
        raise Exception("创建Flavor失败,请联系运营商")

this is the retrieveFlavor function details:

image description

In it, I find_flavor = super_conn.conn.compute.find_flavor(name_or_id=flavor_name)

and it have found the flavor, you can see in the red arrow, but when I step over it get out to the outter:

image description

You can see it comes to the retrieveFlavor invoke place, and the exception is:

'NoneType' object has no attribute '_body'

The strange is

1) the compute.find_flavor() have get the flavor, why still raise Exception? 2) the compute.find_flavor() did not except the Exception, , direct raise to the outter(retrieveFlavor() invoke there).

How to do with that?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2017-11-24 00:58:40 -0500

liaodalin19903 gravatar image

I have found the solution in my aspect.

You see, I use the flavor == None to check whether find the flavor, there comes out my issue, now, if I use if flavor: or if flavor is None:to check whether flavor exists, so I will not get the issue.

there is the knowledge point about foo is None and foo == None.

edit flag offensive delete link more

Comments

thanks for sharing

SGPJ gravatar imageSGPJ ( 2017-12-27 21:13:16 -0500 )edit
0

answered 2017-11-23 08:23:01 -0500

Terry Howe gravatar image

It kind of sounds like a bug in OpenStack SDK. Flavor is an odd one because it doesn't always act like other resources and there might be something going on there. A full stack trace for what is going on in OSC would help it kind of sounds like it gets a response but blows up when you go to use the response probably something related to https://github.com/openstack/python-openstacksdk/blob/master/openstack/resource2.py#L114 (https://github.com/openstack/python-o...)

edit flag offensive delete link more

Comments

@TerryHowe, I find the issue solution in my aspect. see my answer.

liaodalin19903 gravatar imageliaodalin19903 ( 2017-11-24 00:59:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2017-11-23 04:48:43 -0500

Seen: 164 times

Last updated: Nov 24 '17