本文整理汇总了Python中bkr.server.model.PowerType类的典型用法代码示例。如果您正苦于以下问题:Python PowerType类的具体用法?Python PowerType怎么用?Python PowerType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PowerType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_activity_is_not_logged_when_leaving_power_settings_empty
def test_activity_is_not_logged_when_leaving_power_settings_empty(self):
# The bug was that we were recording a change to power_user or
# power_passwd because it changed from NULL to ''.
with session.begin():
self.system.power.power_type = PowerType.lazy_create(name=u'ilo')
self.system.power.power_user = None
self.system.power.power_passwd = None
self.system.power.power_id = None
PowerType.lazy_create(name=u'drac')
self.assertEquals(len(self.system.activity), 0)
b = self.browser
login(b)
self.go_to_system_view(tab='Power Settings')
tab = b.find_element_by_id('power-settings')
# change power type but leave the other fields empty
BootstrapSelect(tab.find_element_by_name('power_type'))\
.select_by_visible_text('drac')
tab.find_element_by_tag_name('form').submit()
tab.find_element_by_xpath('.//span[@class="sync-status" and not(text())]')
with session.begin():
session.refresh(self.system)
self.assertEquals(len(self.system.activity), 1,
'Expecting only one activity row for power_type but found: %r'
% self.system.activity)
self.assertEquals(self.system.activity[0].field_name, u'power_type')
示例2: by_name
def by_name(self,input,*args,**kw):
if 'anywhere' in kw:
search = PowerType.list_by_name(input,find_anywhere=True)
else:
search = PowerType.list_by_name(input)
powers = [elem.name for elem in search]
return dict(matches=powers)
示例3: test_successfully_deleted
def test_successfully_deleted(self):
response = self.s.delete(get_server_base() + 'powertypes/%s' % self.powertype.id)
response.raise_for_status()
with session.begin():
session.expire_all()
with self.assertRaises(NoResultFound):
PowerType.by_name(self.powertype_name)
示例4: delete_powertype
def delete_powertype(id):
"""
Deletes a power type by the given id.
:param id: The id of the power type to be deleted.
:status 204: Power type successfully deleted.
:status 400: Power type is referenced by systems.
:status 404: Power type can not be found.
"""
try:
powertype = PowerType.by_id(id)
except NoResultFound:
raise NotFound404('Power type: %s does not exist' % id)
systems_referenced = System.query.join(System.power).filter(
Power.power_type == powertype).count()
if systems_referenced:
raise BadRequest400('Power type %s still referenced by %i systems' % (
powertype.name, systems_referenced))
session.delete(powertype)
activity = Activity(identity.current.user, u'HTTP', u'Deleted', u'PowerType', powertype.name)
session.add(activity)
return '', 204
示例5: test_creating_a_system_with_power_settings
def test_creating_a_system_with_power_settings(self):
s = requests.Session()
s.post(get_server_base() + 'login', data={'user_name': self.user.user_name,
'password': u'password'}).raise_for_status()
fqdn = data_setup.unique_name(u'newsystem%s')
data = {
'fqdn': fqdn,
'lab_controller_id': self.lc.id,
'power_type': u'apc_snmp_then_etherwake',
'power_address': u'dummyaddress',
'power_user': u'dummyuser',
'power_password': u'dummypassword',
'power_id': u'dummyvm',
'power_quiescent_period': 5,
'release_action': u'LeaveOn',
'reprovision_distro_tree': {'id': self.distro_tree.id},
}
response = post_json(get_server_base() + 'systems/', session=s, data=data)
with session.begin():
system = System.by_fqdn(fqdn, self.user)
self.assertEquals(system.power.power_type, PowerType.by_name(u'apc_snmp_then_etherwake'))
self.assertEquals(system.power.power_address, u'dummyaddress')
self.assertEquals(system.power.power_user, u'dummyuser')
self.assertEquals(system.power.power_passwd, u'dummypassword')
self.assertEquals(system.power.power_id, u'dummyvm')
self.assertEquals(system.power.power_quiescent_period, 5)
self.assertEquals(system.release_action, ReleaseAction.leave_on)
self.assertEquals(system.reprovision_distro_tree, self.distro_tree)
示例6: test_power_quiescent_period_statefulness_not_elapsed
def test_power_quiescent_period_statefulness_not_elapsed(self):
if daemons_running_externally():
raise SkipTest('cannot examine logs of remote beaker-provision')
provision_process, = [p for p in processes if p.name == \
'beaker-provision']
# Initial lookup of this system will reveal no state, so will delay
# for the whole quiescent period
try:
provision_process.start_output_capture()
with session.begin():
system = data_setup.create_system(lab_controller=self.get_lc())
system.power.power_type = PowerType.lazy_create(name=u'dummy')
system.power.power_quiescent_period = 1
system.power.power_id = u'' # make power script not sleep
system.power.delay_until = None
system.action_power(action=u'off', service=u'testdata')
wait_for_commands_to_finish(system, timeout=10)
finally:
provision_output = provision_process.finish_output_capture()
self.assertIn('Entering quiescent period, delaying 1 seconds for '
'command %s' % system.command_queue[0].id, provision_output)
# Increase the quiescent period, to ensure we enter it
try:
provision_process.start_output_capture()
with session.begin():
system = System.by_id(system.id, User.by_user_name('admin'))
system.power.power_quiescent_period = 10
system.action_power(action=u'on', service=u'testdata')
wait_for_commands_to_finish(system, timeout=15)
finally:
provision_output = provision_process.finish_output_capture()
self.assertIn('Entering quiescent period', provision_output)
示例7: test_power_commands_are_not_run_twice
def test_power_commands_are_not_run_twice(self):
# We will make the dummy power script sleep for this long:
power_sleep = 4
# To reproduce this bug, we need to queue up three commands for the
# same system (so they are run in sequence by beaker-provision), where
# the commands take enough time that the second one will still be
# running on the next iteration of the polling loop. The third command
# will be run twice.
assert power_sleep < get_conf().get('SLEEP_TIME')
assert 2 * power_sleep > get_conf().get('SLEEP_TIME')
with session.begin():
system = data_setup.create_system(lab_controller=self.get_lc())
system.power.power_type = PowerType.lazy_create(name=u'dummy')
system.power.power_id = power_sleep # make power script sleep
system.action_power(action=u'off', service=u'testdata')
system.action_power(action=u'off', service=u'testdata')
system.action_power(action=u'off', service=u'testdata')
wait_for_commands_to_finish(system, timeout=5 * power_sleep)
with session.begin():
session.expire_all()
self.assertEquals(system.command_queue[0].status, CommandStatus.completed)
self.assertEquals(system.command_queue[1].status, CommandStatus.completed)
self.assertEquals(system.command_queue[2].status, CommandStatus.completed)
# The bug manifests as two "Completed" records for the power
# command which ran twice
self.assertEquals(system.dyn_activity
.filter_by(field_name=u'Power', new_value=u'Completed')
.count(), 3)
示例8: test_power_quiescent_period
def test_power_quiescent_period(self):
# Test that we do in fact wait for the quiescent period to pass
# before running a command
if daemons_running_externally():
raise SkipTest('cannot examine logs of remote beaker-provision')
provision_process, = [p for p in processes if p.name == \
'beaker-provision']
# These times are needed to guarantee that we are actually waiting for
# the quiescent period and not waiting for another poll loop
quiescent_period = get_conf().get('SLEEP_TIME') * 3
timeout = get_conf().get('SLEEP_TIME') * 2
try:
provision_process.start_output_capture()
with session.begin():
system = data_setup.create_system(lab_controller=self.get_lc())
system.power.power_type = PowerType.lazy_create(name=u'dummy')
system.power.power_quiescent_period = quiescent_period
system.power.power_id = u'' # make power script not sleep
system.power.delay_until = None
system.action_power(action=u'off', service=u'testdata')
wait_for_commands_completed(system, timeout=timeout)
self.fail('The quiescent period is not being respected')
except AssertionError:
# wait_for_commands() should timeout if the quiescent period is
#respected
pass
finally:
provision_output = provision_process.finish_output_capture()
# The initial command seen for a system will always wait for the full
# quiescent period
self.assertIn('Entering quiescent period, delaying %s seconds for '
'command %s' % (quiescent_period, system.command_queue[0].id),
provision_output)
示例9: create_powertype
def create_powertype():
"""
Creates a new power type. The request must be :mimetype:`application/json`.
:jsonparam string name: Name for the power type.
:status 201: The power type was successfully created.
"""
data = read_json_request(request)
with convert_internal_errors():
if PowerType.query.filter_by(**data).count():
raise Conflict409('Power type %s already exists' % data['name'])
powertype = PowerType(**data)
activity = Activity(identity.current.user, u'HTTP', u'Created', u'PowerType', powertype.name)
session.add_all([powertype, activity])
response = jsonify(powertype.__json__())
response.status_code = 201
return response
示例10: save
def save(self, **kw):
if kw['id']:
edit = PowerType.by_id(kw['id'])
edit.name = kw['name']
elif kw.get('name'):
new = PowerType(name=kw['name'])
else:
flash(_(u"Invalid Power Type entry"))
redirect(".")
flash( _(u"OK") )
redirect(".")
示例11: configure_system_power
def configure_system_power(system, power_type=u'ilo', address=None,
user=None, password=None, power_id=None):
if address is None:
address = u'%s_power_address' % system.fqdn
if user is None:
user = u'%s_power_user' % system.fqdn
if password is None:
password = u'%s_power_password' % system.fqdn
if power_id is None:
power_id = unique_name(u'%s')
system.power = Power(power_type=PowerType.by_name(power_type),
power_address=address, power_id=power_id,
power_user=user, power_passwd=password)
示例12: test_power_quiescent_period
def test_power_quiescent_period(self):
# Test that we do in fact wait for the quiescent period to pass
# before running a command.
# This time is needed to guarantee that we are actually waiting for
# the quiescent period and not waiting for another poll loop:
quiescent_period = get_conf().get('SLEEP_TIME') * 3
with session.begin():
system = data_setup.create_system(lab_controller=self.get_lc())
system.power.power_type = PowerType.lazy_create(name=u'dummy')
system.power.power_quiescent_period = quiescent_period
system.power.power_id = u'' # make power script not sleep
system.power.delay_until = None
system.action_power(action=u'off', service=u'testdata')
command = system.command_queue[0]
assert_command_is_delayed(command, quiescent_period - 0.5, 10)
示例13: test_quiescent_period_is_obeyed_for_consecutive_commands
def test_quiescent_period_is_obeyed_for_consecutive_commands(self):
quiescent_period = 3
with session.begin():
system = data_setup.create_system(lab_controller=self.get_lc())
system.power.power_type = PowerType.lazy_create(name=u'dummy')
system.power.power_quiescent_period = quiescent_period
system.power.power_id = u'' # make power script not sleep
system.power.delay_until = None
system.action_power(action=u'on', service=u'testdata')
system.action_power(action=u'on', service=u'testdata')
system.action_power(action=u'on', service=u'testdata')
commands = system.command_queue[:3]
assert_command_is_delayed(commands[2], quiescent_period - 0.5, 10)
assert_command_is_delayed(commands[1], quiescent_period - 0.5, 10)
assert_command_is_delayed(commands[0], quiescent_period - 0.5, 10)
示例14: edit
def edit(self,**kw):
values = []
if kw.get('id'):
powertype = PowerType.by_id(kw['id'])
values = dict(
id = powertype.id,
name = powertype.name,
)
return dict(
form = self.form,
action = './save',
options = {},
value = values,
)
示例15: test_create_new_powertype_successfully
def test_create_new_powertype_successfully(self):
with session.begin():
activity_count = Activity.query.count()
login(self.s, self.admin_user, self.admin_password)
expected_name = 'beerpower'
response = post_json(get_server_base() + 'powertypes/',
session=self.s,
data=dict(name=expected_name))
self.assertEqual(201, response.status_code)
self.assertEqual(expected_name, response.json()['name'])
with session.begin():
powertype = PowerType.by_name(expected_name)
self.assertEqual(expected_name, powertype.name)
self.assertEqual(activity_count + 1, Activity.query.count())