Skip to content

Commit df296ad

Browse files
authored
Merge pull request #1460 from jasonrahm/fix.examplefiles
Issue #1457 - Allow Example Resource to Load
2 parents 8dac190 + a4f4607 commit df296ad

2 files changed

Lines changed: 55 additions & 8 deletions

File tree

f5/bigip/resource.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -683,14 +683,30 @@ def _produce_instance(self, response):
683683
# Post-process the response
684684
new_instance._local_update(response.json())
685685

686-
if new_instance.kind != new_instance._meta_data['required_json_kind'] \
687-
and new_instance.kind != "tm:transaction:commandsstate":
688-
error_message = "For instances of type '%r' the corresponding"\
689-
" kind must be '%r' but creation returned JSON with kind: %r"\
690-
% (new_instance.__class__.__name__,
691-
new_instance._meta_data['required_json_kind'],
692-
new_instance.kind)
693-
raise KindTypeMismatch(error_message)
686+
# Allow for example files, which are KindTypeMismatches
687+
if hasattr(new_instance, 'selfLink'):
688+
if new_instance.kind != new_instance._meta_data[
689+
'required_json_kind'] \
690+
and new_instance.kind != "tm:transaction:commandsstate" \
691+
and 'example' not in new_instance.selfLink.split('/')[-1]:
692+
error_message = "For instances of type '%r' the corresponding" \
693+
" kind must be '%r' but creation returned JSON with kind: %r" \
694+
% (new_instance.__class__.__name__,
695+
new_instance._meta_data[
696+
'required_json_kind'],
697+
new_instance.kind)
698+
raise KindTypeMismatch(error_message)
699+
else:
700+
if new_instance.kind != new_instance._meta_data[
701+
'required_json_kind'] \
702+
and new_instance.kind != "tm:transaction:commandsstate":
703+
error_message = "For instances of type '%r' the corresponding" \
704+
" kind must be '%r' but creation returned JSON with kind: %r" \
705+
% (new_instance.__class__.__name__,
706+
new_instance._meta_data[
707+
'required_json_kind'],
708+
new_instance.kind)
709+
raise KindTypeMismatch(error_message)
694710

695711
# Update the object to have the correct functional uri.
696712
new_instance._activate_URI(new_instance.selfLink)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2018 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import pytest
17+
18+
from icontrol.exceptions import iControlUnexpectedHTTPError
19+
20+
21+
def test_create_example_resource(request, mgmt_root):
22+
with pytest.raises(iControlUnexpectedHTTPError) as error:
23+
mgmt_root.tm.ltm.pools.pool.create(name='example')
24+
assert 'is a reserved keyword and must not be used as resource name' in str(error.value.message)
25+
26+
27+
def test_load_example_resource(request, mgmt_root):
28+
x = mgmt_root.tm.ltm.pools.pool.load(name='example')
29+
assert x.kind == 'tm:ltm:pool:poolcollectionstate'
30+
assert x.kind != 'tm:ltm:pool:poolstate'
31+
assert x.items[0].get('name') is None

0 commit comments

Comments
 (0)