1) Rename replicationcontroller.py to replicationcontrollers.py 2) Add pod_data support in client (backend will be updated later) Change-Id: If315873a02bc896129e2ba41eb2a3d6fdd10b5ed Closes-Bug: #1410447
		
			
				
	
	
		
			125 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			125 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# Copyright 2015 IBM Corp.
 | 
						|
#
 | 
						|
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
						|
#    not use this file except in compliance with the License. You may obtain
 | 
						|
#    a copy of the License at
 | 
						|
#
 | 
						|
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
#
 | 
						|
#    Unless required by applicable law or agreed to in writing, software
 | 
						|
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
						|
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
						|
#    License for the specific language governing permissions and limitations
 | 
						|
#    under the License.
 | 
						|
 | 
						|
import copy
 | 
						|
 | 
						|
import testtools
 | 
						|
from testtools import matchers
 | 
						|
 | 
						|
from magnumclient.tests import utils
 | 
						|
from magnumclient.v1 import replicationcontrollers as rcs
 | 
						|
 | 
						|
 | 
						|
RC1 = {'id': 123,
 | 
						|
       'uuid': '66666666-7777-8888-9999-000000000001',
 | 
						|
       'name': 'rc1',
 | 
						|
       'images': ['image1'],
 | 
						|
       'bay_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a51',
 | 
						|
       'selector': {'name': 'bar1'},
 | 
						|
       'replicas': 1
 | 
						|
       }
 | 
						|
RC2 = {'id': 124,
 | 
						|
       'uuid': '66666666-7777-8888-9999-000000000002',
 | 
						|
       'name': 'rc2',
 | 
						|
       'images': ['image2'],
 | 
						|
       'bay_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
 | 
						|
       'selector': {'name': 'bar2'},
 | 
						|
       'replicas': 2
 | 
						|
       }
 | 
						|
CREATE_RC = {'rc_definition_url': 'file:///a/b.json'}
 | 
						|
UPDATED_RC = copy.deepcopy(RC1)
 | 
						|
NEW_REPLICAS = 3
 | 
						|
UPDATED_RC['replicas'] = NEW_REPLICAS
 | 
						|
 | 
						|
fake_responses = {
 | 
						|
    '/v1/rcs':
 | 
						|
    {
 | 
						|
        'GET': (
 | 
						|
            {},
 | 
						|
            {'rcs': [RC1, RC2]},
 | 
						|
        ),
 | 
						|
        'POST': (
 | 
						|
            {},
 | 
						|
            CREATE_RC,
 | 
						|
        ),
 | 
						|
    },
 | 
						|
    '/v1/rcs/%s' % RC1['id']:
 | 
						|
    {
 | 
						|
        'GET': (
 | 
						|
            {},
 | 
						|
            RC1
 | 
						|
        ),
 | 
						|
        'DELETE': (
 | 
						|
            {},
 | 
						|
            None,
 | 
						|
        ),
 | 
						|
        'PATCH': (
 | 
						|
            {},
 | 
						|
            UPDATED_RC,
 | 
						|
        ),
 | 
						|
    },
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
class RCManagerTest(testtools.TestCase):
 | 
						|
 | 
						|
    def setUp(self):
 | 
						|
        super(RCManagerTest, self).setUp()
 | 
						|
        self.api = utils.FakeAPI(fake_responses)
 | 
						|
        self.mgr = rcs.ReplicationControllerManager(self.api)
 | 
						|
 | 
						|
    def test_rc_list(self):
 | 
						|
        rcs = self.mgr.list()
 | 
						|
        expect = [
 | 
						|
            ('GET', '/v1/rcs', {}, None),
 | 
						|
        ]
 | 
						|
        self.assertEqual(expect, self.api.calls)
 | 
						|
        self.assertThat(rcs, matchers.HasLength(2))
 | 
						|
 | 
						|
    def test_rc_show(self):
 | 
						|
        rc = self.mgr.get(RC1['id'])
 | 
						|
        expect = [
 | 
						|
            ('GET', '/v1/rcs/%s' % RC1['id'], {}, None)
 | 
						|
        ]
 | 
						|
        self.assertEqual(expect, self.api.calls)
 | 
						|
        self.assertEqual(RC1['name'], rc.name)
 | 
						|
        self.assertEqual(RC1['replicas'], rc.replicas)
 | 
						|
 | 
						|
    def test_rc_create(self):
 | 
						|
        rc = self.mgr.create(**CREATE_RC)
 | 
						|
        expect = [
 | 
						|
            ('POST', '/v1/rcs', {}, CREATE_RC),
 | 
						|
        ]
 | 
						|
        self.assertEqual(expect, self.api.calls)
 | 
						|
        self.assertTrue(rc)
 | 
						|
 | 
						|
    def test_rc_delete(self):
 | 
						|
        rc = self.mgr.delete(RC1['id'])
 | 
						|
        expect = [
 | 
						|
            ('DELETE', '/v1/rcs/%s' % RC1['id'], {}, None),
 | 
						|
        ]
 | 
						|
        self.assertEqual(expect, self.api.calls)
 | 
						|
        self.assertIsNone(rc)
 | 
						|
 | 
						|
    def test_rc_update(self):
 | 
						|
        patch = {'op': 'replace',
 | 
						|
                 'value': NEW_REPLICAS,
 | 
						|
                 'path': '/replicas'}
 | 
						|
        rc = self.mgr.update(id=RC1['id'], patch=patch)
 | 
						|
        expect = [
 | 
						|
            ('PATCH', '/v1/rcs/%s' % RC1['id'], {}, patch),
 | 
						|
        ]
 | 
						|
        self.assertEqual(expect, self.api.calls)
 | 
						|
        self.assertEqual(NEW_REPLICAS, rc.replicas)
 |