pep8
This commit is contained in:
@@ -12,4 +12,4 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Collection of code for setting up and testing iscsi-connector charm."""
|
||||
"""Collection of code for setting up and testing iscsi-connector charm."""
|
||||
|
||||
@@ -14,22 +14,9 @@
|
||||
|
||||
"""Code for setting up iscsi-connector tests."""
|
||||
|
||||
# """
|
||||
# steps for testing without password:
|
||||
# - deploy ubuntu for storage
|
||||
# - deploy ubuntu for initiator
|
||||
# configure that unit:
|
||||
# - install tgt -y
|
||||
# - configure iscsi target
|
||||
# - need to know the initiator ip
|
||||
# - restart tgt
|
||||
# - configure ubuntu initiator with init dict, target, port
|
||||
# """
|
||||
|
||||
import logging
|
||||
|
||||
import zaza.model
|
||||
import zaza.openstack.utilities.openstack as openstack_utils
|
||||
|
||||
|
||||
def basic_target_setup():
|
||||
@@ -45,7 +32,9 @@ def basic_target_setup():
|
||||
unit.entity_id,
|
||||
cmd)
|
||||
|
||||
|
||||
def configure_iscsi_target():
|
||||
"""Configure the iscsi target."""
|
||||
lun = 'iqn.2020-07.canonical.com:lun1'
|
||||
backing_store = 'dev/vdb'
|
||||
initiator_address = zaza.model.get_app_ips('ubuntu')[0]
|
||||
@@ -54,13 +43,18 @@ def configure_iscsi_target():
|
||||
username_in = 'iscsi-target'
|
||||
password_in = 'secretpass'
|
||||
write_file = (
|
||||
"""echo -e '<target {}>\n\tbacking-store {}\n\tinitiator-address {}\n\tincominguser {} {}\n\t"""
|
||||
"""outgoinguser {} {}\n</target>' | sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun, backing_store,
|
||||
initiator_address, username, password, username_in, password_in)
|
||||
"""echo -e '<target {}>\n\tbacking-store {}\n\tinitiator-address """
|
||||
"""{}\n\tincominguser {} {}\n\toutgoinguser {} {}\n</target>' """
|
||||
""" | sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun,
|
||||
backing_store,
|
||||
initiator_address,
|
||||
username,
|
||||
password,
|
||||
username_in,
|
||||
password_in)
|
||||
)
|
||||
logging.info('Writing target iscsi.conf')
|
||||
zaza.model.run_on_unit('ubuntu-target/0', write_file)
|
||||
# Restart tgt to load new config
|
||||
restart_tgt = "systemctl restart tgt"
|
||||
zaza.model.run_on_unit('ubuntu-target/0', restart_tgt)
|
||||
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
|
||||
import json
|
||||
import logging
|
||||
import tempfile
|
||||
|
||||
import zaza.model
|
||||
import zaza.openstack.charm_tests.test_utils as test_utils
|
||||
import zaza.openstack.utilities.generic as generic_utils
|
||||
|
||||
|
||||
class ISCSIConnectorTest(test_utils.BaseCharmTest):
|
||||
@@ -32,10 +30,11 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest):
|
||||
super(ISCSIConnectorTest, cls).setUpClass()
|
||||
|
||||
def configure_iscsi_connector(self):
|
||||
"""Configure iscsi connector."""
|
||||
iqn = 'iqn.2020-07.canonical.com:lun1'
|
||||
unit_fqdn = self.get_unit_full_hostname('ubuntu')
|
||||
target_ip = zaza.model.get_app_ips('ubuntu-target')[0]
|
||||
initiator_dictionary = json.dumps({unit_fqdn:iqn})
|
||||
initiator_dictionary = json.dumps({unit_fqdn: iqn})
|
||||
conf = {
|
||||
'initiator-dictionary': initiator_dictionary,
|
||||
'target': target_ip,
|
||||
@@ -56,13 +55,18 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest):
|
||||
return hostname
|
||||
|
||||
def test_iscsi_connector(self):
|
||||
"""Test iscsi configuration and wait for idle status."""
|
||||
self.configure_iscsi_connector()
|
||||
logging.info('Wait for idle/ready status...')
|
||||
zaza.model.wait_for_application_states()
|
||||
|
||||
|
||||
def test_validate_iscsi_session(self):
|
||||
"""Validate that the iscsi session is active."""
|
||||
unit = zaza.model.get_units('ubuntu')[0]
|
||||
logging.info('Checking if iscsi session is active.')
|
||||
run = zaza.model.run_on_unit(unit.entity_id, 'iscsiadm -m session')
|
||||
logging.info('iscsiadm -m session: Stdout: {}, Stderr: {}, Code: {}'.format(run['Stdout'], run['Stderr'], run['Code']))
|
||||
logging.info("""iscsiadm -m session: Stdout: {}, Stderr: {}, """
|
||||
"""Code: {}""".format(run['Stdout'],
|
||||
run['Stderr'],
|
||||
run['Code']))
|
||||
assert run['Code'] == '0'
|
||||
|
||||
Reference in New Issue
Block a user