示例#1
0
    def test_setup_failexists(self, mock_clients):
        # Setup and mock
        new_context = copy.deepcopy(self.context)
        new_context["flavors"] = {}

        mock_flavor_create = mock_clients().nova().flavors.create

        exception = nova_exceptions.Conflict("conflict")
        mock_flavor_create.side_effect = exception

        # Run
        flavors_ctx = flavors.FlavorsGenerator(self.context)
        flavors_ctx.setup()

        # Assertions
        self.assertEqual(new_context, flavors_ctx.context)

        mock_clients.assert_called_with(self.context["admin"]["credential"])

        mock_flavor_create.assert_called_once_with(name="flavor_name",
                                                   ram=2048,
                                                   vcpus=3,
                                                   disk=10,
                                                   ephemeral=3,
                                                   swap=5)
示例#2
0
    def test_attach_network_or_port_conflict_exception(self):
        self.manager.manager.interface_attach.side_effect = (
            nova_exceptions.Conflict('test_exception'))
        interface_mock = mock.MagicMock()
        interface_mock.id = self.port_id
        bad_interface_mock = mock.MagicMock()
        bad_interface_mock.id = uuidutils.generate_uuid()
        self.manager.manager.interface_list.side_effect = [
            [interface_mock], [bad_interface_mock], [], Exception('boom')]

        # No port specified
        self.assertRaises(exceptions.ComputeUnknownException,
                          self.manager.attach_network_or_port,
                          self.compute_id, self.network_id)

        # Port already attached
        result = self.manager.attach_network_or_port(self.compute_id,
                                                     port_id=self.port_id)
        self.assertEqual(interface_mock, result)

        # Port not found
        self.assertRaises(exceptions.ComputePortInUseException,
                          self.manager.attach_network_or_port,
                          self.compute_id, port_id=self.port_id)

        # No ports attached
        self.assertRaises(exceptions.ComputePortInUseException,
                          self.manager.attach_network_or_port,
                          self.compute_id, port_id=self.port_id)

        # Get attached ports list exception
        self.assertRaises(exceptions.ComputeUnknownException,
                          self.manager.attach_network_or_port,
                          self.compute_id, port_id=self.port_id)
 def test_remove_computehosts_with_duplicate_host(self):
     self._patch_get_aggregate_from_name_or_id()
     self.nova.aggregates.add_host.side_effect = (
         nova_exceptions.Conflict(409))
     self.assertRaises(manager_exceptions.CantAddHost,
                       self.pool.remove_computehost,
                       'pool',
                       'host3')
示例#4
0
 def test_power_on_conflict(self, mock_active, mock_nova, mock_log,
                            mock_init):
     self._create_bmc(mock_nova)
     mock_active.return_value = False
     self.mock_client.servers.start.side_effect = exceptions.Conflict('a')
     self.bmc.power_on()
     self.mock_client.servers.start.assert_called_once_with('abc-123')
     mock_log.assert_called_once_with('Ignoring exception: '
                                      '"Conflict (HTTP a)"')
示例#5
0
    def test_keypair_fail_to_create_because_already_exists(self, nc):
        request = self.mock_rest_request(GET={})

        conflict_exception = exceptions.Conflict(409, 'keypair exists!')
        nc.keypair_create.side_effect = conflict_exception

        with mock.patch.object(settings, 'DEBUG', True):
            response = nova.Keypair().get(request, "Ni!")

        self.assertEqual(409, response.status_code)
示例#6
0
 def test_create_key_pair_invalid(self):
     self.nova.keypairs.create.side_effect = (nova_exception.Conflict(409))
     self.assert_execution_error('InvalidKeyPair.Duplicate',
                                 'CreateKeyPair',
                                 {'KeyName': fakes.NAME_KEY_PAIR})
     self.assert_execution_error('ValidationError', 'CreateKeyPair',
                                 {'KeyName': 'k' * 256})
     self.nova.keypairs.create.side_effect = (nova_exception.OverLimit(413))
     self.assert_execution_error('ResourceLimitExceeded', 'CreateKeyPair',
                                 {'KeyName': fakes.NAME_KEY_PAIR})
示例#7
0
    def create_keypair(self, keypair_name):
        ''' Create euca keypair then generate a public_key using commandline
        ssh-keygen.'''
        try:
            resp = self.conn.ex_create_keypair(name=keypair_name)
            resp['name'] = keypair_name
            resp['private_key'] = resp['keyMaterial']
            resp['fingerprint'] = resp['keyFingerprint']

            #TODO use a library to do this
            command = " ".join([
                "/bin/echo -e ",
                "'%s'" % resp['private_key'].replace('\n', '\\n'), "|",
                self.SSH_KEYGEN, "-y -f /dev/stdin"
            ])

            process = Popen(command, stdout=PIPE, shell=True)
            resp['public_key'] = process.communicate()[0]

            return resp
        except Exception:
            raise nova_exceptions.Conflict(
                409, message="Key pair '%s' already exists." % keypair_name)
 def test_ensure_flavor_exists(self):
     mock_nova, mock_flavor = self._create_flavor_mocks()
     mock_nova.flavors.create.side_effect = exceptions.Conflict(None)
     undercloud._ensure_flavor(mock_nova, 'test')
     mock_flavor.set_keys.assert_not_called()
示例#9
0
 def raise_exception(resource_id):
     raise nova_exceptions.Conflict(409)