Commit 2d0be8f9 authored by ibuler's avatar ibuler

[git status

parent b97d5b09
......@@ -39,7 +39,7 @@ TEST_ASSET_CONN_TASK_NAME = "ASSET_CONN_TEST_MANUAL"
TEST_SYSTEM_USER_CONN_PERIOD_LOCK_KEY = "TEST_SYSTEM_USER_CONN_PERIOD_KEY"
TEST_SYSTEM_USER_CONN_PERIOD_TASK_NAME = "TEST-SYSTEM-USER-CONN-PERIOD-TASK"
TEST_SYSTEM_USER_CONN_CACHE_KEY_PREFIX = "SYSTEM_USER_CONN_"
TEST_SYSTEM_USER_CONN_TASK_NAME = "TEST-ADMIN-USER-CONN-{}"
TEST_SYSTEM_USER_CONN_TASK_NAME = "TEST-SYSTEM-USER-CONN-{}"
TEST_SYSTEM_USER_CONN_LOCK_KEY = "TEST_SYSTEM_USER_CONN_{}"
SYSTEM_USER_CONN_CACHE_KEY = "SYSTEM_USER_CONN_{}"
TEST_SYSTEM_USER_CONN_TASKS = [
......@@ -52,6 +52,6 @@ TEST_SYSTEM_USER_CONN_TASKS = [
]
TASK_OPTIONS = {
'timeout': 60,
'timeout': 10,
'forks': 10,
}
......@@ -114,6 +114,16 @@ class AssetUser(models.Model):
private_key=private_key,
public_key=public_key)
def _to_secret_json(self):
"""Push system user use it"""
return {
'name': self.name,
'username': self.username,
'password': self.password,
'public_key': self.public_key,
'private_key': self.private_key_file,
}
class Meta:
abstract = True
......@@ -195,18 +205,6 @@ class SystemUser(AssetUser):
def __str__(self):
return self.name
def _to_secret_json(self):
"""Push system user use it"""
return {
'name': self.name,
'username': self.username,
'shell': self.shell,
'sudo': self.sudo,
'password': self.password,
'public_key': self.public_key,
'private_key_file': self.private_key_file,
}
def get_clusters_assets(self):
from .asset import Asset
clusters = self.cluster.all()
......
......@@ -173,7 +173,10 @@ def test_admin_user_connectability_manual(asset, task_name=None):
task_name = const.TEST_ASSET_CONN_TASK_NAME
hosts = [asset.hostname]
tasks = const.TEST_ADMIN_USER_CONN_TASKS
task = create_or_update_task(task_name, tasks=tasks, hosts=hosts)
task = create_or_update_task(
task_name, tasks=tasks, hosts=hosts, run_as_admin=True,
created_by='System', options=const.TASK_OPTIONS, pattern='all',
)
result = task.run()
if result.results_summary['dark']:
......@@ -194,7 +197,7 @@ def test_system_user_connectability(system_user, force=False):
"""
from ops.utils import create_or_update_task
lock_key = const.TEST_SYSTEM_USER_CONN_LOCK_KEY.format(system_user.name)
task_name = const.TEST_SYSTEM_USER_CONN_TASK_NAME
task_name = const.TEST_SYSTEM_USER_CONN_TASK_NAME.format(system_user.name)
if cache.get(lock_key, 0) == 1 and not force:
logger.debug("Task {} is running or before long, passed this time".format(task_name))
return {}
......@@ -202,7 +205,8 @@ def test_system_user_connectability(system_user, force=False):
hosts = [asset.hostname for asset in assets]
tasks = const.TEST_SYSTEM_USER_CONN_TASKS
task = create_or_update_task(
task_name, hosts=hosts, tasks=tasks, options=const.TASK_OPTIONS,
task_name, hosts=hosts, tasks=tasks, pattern='all',
options=const.TASK_OPTIONS,
run_as=system_user.name, created_by="System",
)
cache.set(lock_key, 1, CACHE_MAX_TIME)
......
......@@ -57,7 +57,7 @@ def int_to_str(value):
def ts_to_date(ts):
try:
ts = float(ts)
except TypeError:
except ValueError:
ts = 0
dt = timezone.datetime.fromtimestamp(ts).\
replace(tzinfo=timezone.get_current_timezone())
......
......@@ -23,7 +23,7 @@ class Task(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'))
is_deleted = models.BooleanField(default=False)
created_by = models.CharField(max_length=128, blank=True, default='')
created_by = models.CharField(max_length=128, blank=True, null=True, default='')
date_created = models.DateTimeField(auto_now_add=True)
__latest_adhoc = None
......@@ -93,13 +93,13 @@ class AdHoc(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
task = models.ForeignKey(Task, related_name='adhoc', on_delete=models.CASCADE)
_tasks = models.TextField(verbose_name=_('Tasks'))
pattern = models.CharField(max_length=64, default='', verbose_name=_('Pattern'))
pattern = models.CharField(max_length=64, default='{}', verbose_name=_('Pattern'))
_options = models.CharField(max_length=1024, default='', verbose_name=_('Options'))
_hosts = models.TextField(blank=True, verbose_name=_('Hosts')) # ['hostname1', 'hostname2']
run_as_admin = models.BooleanField(default=False, verbose_name=_('Run as admin'))
run_as = models.CharField(max_length=128, default='', verbose_name=_("Run as"))
_become = models.CharField(max_length=1024, default='', verbose_name=_("Become"))
created_by = models.CharField(max_length=64, default='', verbose_name=_('Create by'))
created_by = models.CharField(max_length=64, default='', null=True, verbose_name=_('Create by'))
date_created = models.DateTimeField(auto_now_add=True)
@property
......@@ -147,9 +147,10 @@ class AdHoc(models.Model):
@property
def options(self):
if self._options:
return json.loads(self._options)
else:
return {}
_options = json.loads(self._options)
if isinstance(_options, dict):
return _options
return {}
@options.setter
def options(self, item):
......
......@@ -124,8 +124,11 @@ class SessionDetailView(SingleObjectMixin, ListView):
model = Session
object = None
def get(self, request, *args, **kwargs):
self.object = self.get_object(queryset=self.model.objects.all())
return super().get(request, *args, **kwargs)
def get_queryset(self):
self.object = self.get_object()
return command_store.filter(session=self.object.id)
def get_context_data(self, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment