~ubuntu-branches/ubuntu/raring/maas/raring-proposed

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_api.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-17 08:28:36 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20120717082836-ucb2vou8tqg353eq
Tags: 0.1+bzr777+dfsg-0ubuntu1
* New upstream release
* Only run 'maas' command as root. (LP: #974046)
  - debian/extras/maas: Check id.
  - debian/maas.install: Install in 'sbin'.
* debian/maas.postinst:
  - restart apache2 after everything gets processed.
  - Update version to handle upgrades.
* debian/extras/maas-provision: Add wrapper to access 'maasprovisiong'
  command line.
* debian/patches/99_temporary_fix_path.patch: Dropped. No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    create_auth_token,
60
60
    get_auth_tokens,
61
61
    )
 
62
from maasserver.preseed import (
 
63
    get_enlist_preseed,
 
64
    get_preseed,
 
65
    )
62
66
from maasserver.testing import (
63
67
    reload_object,
64
68
    reload_objects,
1393
1397
        self.assertItemsEqual(
1394
1398
            [existing_id], extract_system_ids(parsed_result))
1395
1399
 
 
1400
    def test_GET_list_with_macs_returns_matching_nodes(self):
 
1401
        # The "list" operation takes optional "mac_address" parameters.  Only
 
1402
        # nodes with matching MAC addresses will be returned.
 
1403
        macs = [factory.make_mac_address() for counter in range(3)]
 
1404
        matching_mac = macs[0].mac_address
 
1405
        matching_system_id = macs[0].node.system_id
 
1406
        response = self.client.get(self.get_uri('nodes/'), {
 
1407
            'op': 'list',
 
1408
            'mac_address': [matching_mac],
 
1409
        })
 
1410
        parsed_result = json.loads(response.content)
 
1411
        self.assertItemsEqual(
 
1412
            [matching_system_id], extract_system_ids(parsed_result))
 
1413
 
1396
1414
    def test_GET_list_allocated_returns_only_allocated_with_user_token(self):
1397
1415
        # If the user's allocated nodes have different session tokens,
1398
1416
        # list_allocated should only return the nodes that have the
2226
2244
        return {
2227
2245
                'arch': "armhf",
2228
2246
                'subarch': "armadaxp",
2229
 
                'mac': "AA:BB:CC:DD:EE:FF",
 
2247
                'mac': factory.make_mac_address().mac_address,
2230
2248
                'menutitle': "menutitle",
2231
2249
                'kernelimage': "/my/kernel",
2232
2250
                'append': "append",
2275
2293
            }
2276
2294
        self.assertEqual(expected, observed)
2277
2295
 
 
2296
    def test_compose_enlistment_preseed_url_links_to_enlistment_preseed(self):
 
2297
        response = self.client.get(api.compose_enlistment_preseed_url())
 
2298
        self.assertEqual(
 
2299
            (httplib.OK, get_enlist_preseed()),
 
2300
            (response.status_code, response.content))
 
2301
 
 
2302
    def test_compose_preseed_url_links_to_preseed_for_node(self):
 
2303
        node = factory.make_node()
 
2304
        response = self.client.get(api.compose_preseed_url(node))
 
2305
        self.assertEqual(
 
2306
            (httplib.OK, get_preseed(node)),
 
2307
            (response.status_code, response.content))
 
2308
 
 
2309
    def test_compose_preseed_kernel_opt_returns_option_for_known_node(self):
 
2310
        mac = factory.make_mac_address()
 
2311
        self.assertEqual(
 
2312
            "auto url=%s" % api.compose_preseed_url(mac.node),
 
2313
            api.compose_preseed_kernel_opt(mac.mac_address))
 
2314
 
 
2315
    def test_compose_preseed_kernel_opt_returns_option_for_unknown_node(self):
 
2316
        self.assertEqual(
 
2317
            "auto url=%s" % api.compose_enlistment_preseed_url(),
 
2318
            api.compose_preseed_kernel_opt(factory.getRandomMACAddress()))
 
2319
 
 
2320
    def test_pxe_config_appends_enlistment_preseed_url_for_unknown_node(self):
 
2321
        params = self.get_params()
 
2322
        params['mac'] = factory.getRandomMACAddress()
 
2323
        response = self.client.get(reverse('pxeconfig'), params)
 
2324
        self.assertIn(api.compose_enlistment_preseed_url(), response.content)
 
2325
 
 
2326
    def test_pxe_config_appends_preseed_url_for_known_node(self):
 
2327
        params = self.get_params()
 
2328
        node = MACAddress.objects.get(mac_address=params['mac']).node
 
2329
        response = self.client.get(reverse('pxeconfig'), params)
 
2330
        self.assertIn(api.compose_preseed_url(node), response.content)
 
2331
 
2278
2332
 
2279
2333
class TestNodeGroupsAPI(APITestCase):
2280
2334