add account attributes to disabled ec2-classic mode

update unit test

Change-Id: I9cc68c4c8c39f7fe1b736434c706709209d1f0a4
This commit is contained in:
tikitavi 2017-01-19 00:28:50 +03:00
parent 8fc0ad70bc
commit 441c19f8d2
2 changed files with 44 additions and 5 deletions

View File

@ -12,12 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import functools
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import netutils
from ec2api.api import common
from ec2api.api import ec2utils
from ec2api import clients
from ec2api.db import api as db_api
from ec2api import exception
@ -139,7 +143,8 @@ def describe_account_attributes(context, attribute_name=None):
attribute_getters = {
'supported-platforms': (
account_attribute_engine.get_supported_platforms),
'default-vpc': account_attribute_engine.get_default_vpc,
'default-vpc': functools.partial(
account_attribute_engine.get_default_vpc, context),
'max-instances': get_max_instances,
}
@ -197,9 +202,18 @@ def _describe_verbose(context):
class AccountAttributeEngineNeutron(object):
def get_supported_platforms(self):
return ['EC2', 'VPC']
if CONF.disable_ec2_classic:
return ['VPC']
else:
return ['EC2', 'VPC']
def get_default_vpc(self):
def get_default_vpc(self, context):
if CONF.disable_ec2_classic:
ec2utils.check_and_create_default_vpc(context)
vpc = next((vpc for vpc in db_api.get_items(context, 'vpc')
if vpc.get('is_default')), None)
if vpc:
return vpc['id']
return 'none'
@ -208,7 +222,7 @@ class AccountAttributeEngineNova(object):
def get_supported_platforms(self):
return ['EC2']
def get_default_vpc(self):
def get_default_vpc(self, context):
return 'none'

View File

@ -60,7 +60,8 @@ class AvailabilityZoneCase(base.ApiTestCase):
self.assertTrue(resp['regionInfo'][0].get('regionEndpoint')
is not None)
def test_describe_account_attributes(self):
@mock.patch('ec2api.api.ec2utils.check_and_create_default_vpc')
def test_describe_account_attributes(self, check_and_create):
self.nova.quotas.get.return_value = mock.Mock(instances=77)
availability_zone.account_attribute_engine = (
@ -114,3 +115,27 @@ class AvailabilityZoneCase(base.ApiTestCase):
self.assert_execution_error('InvalidParameter',
'DescribeAccountAttributes',
{'AttributeName.1': 'fake'})
self.configure(disable_ec2_classic=True)
availability_zone.account_attribute_engine = (
availability_zone.AccountAttributeEngineNeutron())
def mock_check_and_create(context):
self.set_mock_db_items(fakes.DB_VPC_DEFAULT)
check_and_create.side_effect = mock_check_and_create
resp = self.execute('DescribeAccountAttributes', {})
self.assertThat(resp['accountAttributeSet'],
matchers.ListMatches(
[{'attributeName': 'supported-platforms',
'attributeValueSet': [
{'attributeValue': 'VPC'}]},
{'attributeName': 'default-vpc',
'attributeValueSet': [
{'attributeValue':
fakes.ID_EC2_VPC_DEFAULT}]},
{'attributeName': 'max-instances',
'attributeValueSet': [
{'attributeValue': 77}]}],
orderless_lists=True))
check_and_create.assert_called_once_with(mock.ANY)